K = int(eval(input()))



A = [0]*1000001

A[0] = 7%K

ans = -1



for i in range(1,1000001):

    A[i] = (A[i-1]*10+7)%K



for i in range(1000001):

    if A[i]==0:

        ans = i+1

        break

        

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



ans = -1

mod = 7%K

for i in range(1000001):

    if mod==0:

        ans = i+1

        break

    else:

        mod = (mod*10+7)%K

        

print(ans)
K = int(eval(input()))
A = [0] * 1000001
A[0] = 7 % K
ans = -1
for i in range(1, 1000001):
    A[i] = (A[i - 1] * 10 + 7) % K
for i in range(1000001):
    if A[i] == 0:
        ans = i + 1
        break
print(ans)

K = int(eval(input()))
ans = -1
mod = 7 % K
for i in range(1000001):
    if mod == 0:
        ans = i + 1
        break
    else:
        mod = (mod * 10 + 7) % K
print(ans)

-A = [0] * 1000001 -A[0] = 7 % K -for i in range(1, 1000001): -    A[i] = (A[i - 1] * 10 + 7) % K +mod = 7 % K -    if A[i] == 0: +    if mod == 0: +    else: +        mod = (mod * 10 + 7) % K