k = int(eval(input()))

x = 7

ans = 1

s = set()

while x%k != 0:

    ans += 1

    x = (x*10%k+7)%k

    if x in s:

        ans = -1

        break

    s.add(x)

print(ans)
k = int(eval(input()))

x = 7

ans = 1

flag = [False]*k

while x%k != 0:

    ans += 1

    x = (x*10%k+7)%k

    if flag[x]:

        ans = -1

        break

    flag[x] = True

print(ans)
k = int(eval(input()))
x = 7
ans = 1
s = set()
while x % k != 0:
    ans += 1
    x = (x * 10 % k + 7) % k
    if x in s:
        ans = -1
        break
    s.add(x)
print(ans)

k = int(eval(input()))
x = 7
ans = 1
flag = [False] * k
while x % k != 0:
    ans += 1
    x = (x * 10 % k + 7) % k
    if flag[x]:
        ans = -1
        break
    flag[x] = True
print(ans)

-s = set() +flag = [False] * k -    if x in s: +    if flag[x]: -    s.add(x) +    flag[x] = True