k = int(eval(input()))

x = 1



if k%7 != 0:

    mod = 9*k

else:

    mod = 9*k//7



for i in range(10**6):

    x = x*10%mod

    if x == 1:

        print((i + 1))

        exit()



print((-1))
k = int(eval(input()))

a = 0



for i in range(k + 10):

    a = (a*10 + 7)%k

    if a == 0:

        print((i + 1))

        exit()

print((-1))
k = int(eval(input()))
x = 1
if k % 7 != 0:
    mod = 9 * k
else:
    mod = 9 * k // 7
for i in range(10**6):
    x = x * 10 % mod
    if x == 1:
        print((i + 1))
        exit()
print((-1))

k = int(eval(input()))
a = 0
for i in range(k + 10):
    a = (a * 10 + 7) % k
    if a == 0:
        print((i + 1))
        exit()
print((-1))

-x = 1 -if k % 7 != 0: -    mod = 9 * k -else: -    mod = 9 * k // 7 -for i in range(10**6): -    x = x * 10 % mod -    if x == 1: +a = 0 +for i in range(k + 10): +    a = (a * 10 + 7) % k +    if a == 0: