K = int(eval(input()))

like = 7

ans = -1

for i in range(K):

    if like % K == 0:

        ans = i+1

        break

    like = (like*10+7) % K

print(ans)

K = int(eval(input()))

ans = -1

N = 7

for i in range(K):

    if N % K == 0:

        ans = i+1

        break

    N = (N*10+7) % K

print(ans)

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

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

-like = 7 +N = 7 -    if like % K == 0: +    if N % K == 0: -    like = (like * 10 + 7) % K +    N = (N * 10 + 7) % K