K = int(eval(input()))



mod = 0

last_mod = 0

for i in range(K):

    if i==0:

        last_mod = 7 % K

    else:

        last_mod = (last_mod*10)%K

    mod += last_mod

    mod %= K

    if mod%K == 0:

        print((i+1))

        exit()

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



mod = 7 % K

for i in range(K):

    if mod == 0:

        print((i+1))

        exit()



    mod = (10*mod + 7) % K



if mod == 0:

    print(K)

else:

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

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

-mod = 0 -last_mod = 0 +mod = 7 % K -    if i == 0: -        last_mod = 7 % K -    else: -        last_mod = (last_mod * 10) % K -    mod += last_mod -    mod %= K -    if mod % K == 0: +    if mod == 0: -print((-1)) +    mod = (10 * mod + 7) % K +if mod == 0: +    print(K) +else: +    print((-1))