K = int(eval(input()))

n = 7%K

r = 1

for i in range(10**6+5):

    if n==0:

        print((i+1))

        exit()

    r *= 10

    n += r*7

    r %= K

    n %= K

    #print(r,n)

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



k = 1

a = 7

for i in range(10**6+5):

    if a%K == 0:

        print(k)

        exit()

    a = (a*10 + 7) % K

    k += 1

    

print((-1))
K = int(eval(input()))
n = 7 % K
r = 1
for i in range(10**6 + 5):
    if n == 0:
        print((i + 1))
        exit()
    r *= 10
    n += r * 7
    r %= K
    n %= K
    # print(r,n)
print((-1))

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

-n = 7 % K -r = 1 +k = 1 +a = 7 -    if n == 0: -        print((i + 1)) +    if a % K == 0: +        print(k) -    r *= 10 -    n += r * 7 -    r %= K -    n %= K -    # print(r,n) +    a = (a * 10 + 7) % K +    k += 1