K = int(eval(input()))



if K % 2 == 0 or K % 5 == 0:

    print((-1))

    exit()



i = 0

sevens = 0

while True:

    sevens += 7 * pow(10, i, K)

    sevens %= K

    i += 1

    if sevens == 0:

        break

print(i)

K = int(eval(input()))



if K % 2 == 0 or K % 5 == 0:

    print((-1))

    exit()



i = 0

ai = 0

while True:

    ai = (ai * 10 + 7) % K

    i += 1

    if ai == 0:

        break

print(i)

K = int(eval(input()))
if K % 2 == 0 or K % 5 == 0:
    print((-1))
    exit()
i = 0
sevens = 0
while True:
    sevens += 7 * pow(10, i, K)
    sevens %= K
    i += 1
    if sevens == 0:
        break
print(i)

K = int(eval(input()))
if K % 2 == 0 or K % 5 == 0:
    print((-1))
    exit()
i = 0
ai = 0
while True:
    ai = (ai * 10 + 7) % K
    i += 1
    if ai == 0:
        break
print(i)

-sevens = 0 +ai = 0 -    sevens += 7 * pow(10, i, K) -    sevens %= K +    ai = (ai * 10 + 7) % K -    if sevens == 0: +    if ai == 0: