k = int(eval(input()))

ans = -1

a = [7%k] * k

for i in range(k - 1):

    a[i + 1] = (10*a[i] + 7) % k

for i in range(k):

    if a[i] == 0:

        ans = i + 1

        break

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

ans = -1

a = 7%k

for i in range(k):

    if a == 0:

        ans = i + 1

        break

    a = (10*a + 7) % k

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

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

-a = [7 % k] * k -for i in range(k - 1): -    a[i + 1] = (10 * a[i] + 7) % k +a = 7 % k -    if a[i] == 0: +    if a == 0: +    a = (10 * a + 7) % k