K = int(eval(input()))

rest = 7%K

count=1

while (count<=K):

    if rest == 0:

        print(count)

        exit()

    count +=1

    rest = (rest%K*10%K + 7%K)%K

print((-1))

K = int(eval(input()))

rest = 7%K

count=1

while (count<=K):

    if rest == 0:

        print(count)

        exit()

    count +=1

    rest = (rest%K*10 + 7)%K

print((-1))
K = int(eval(input()))
rest = 7 % K
count = 1
while count <= K:
    if rest == 0:
        print(count)
        exit()
    count += 1
    rest = (rest % K * 10 % K + 7 % K) % K
print((-1))

K = int(eval(input()))
rest = 7 % K
count = 1
while count <= K:
    if rest == 0:
        print(count)
        exit()
    count += 1
    rest = (rest % K * 10 + 7) % K
print((-1))

-    rest = (rest % K * 10 % K + 7 % K) % K +    rest = (rest % K * 10 + 7) % K