k = int(eval(input()))

checked = [False] * k



surplus = 0

ans = 1

while 1:

    surplus = ((surplus * 10) + 7) % k

    if checked[surplus]:

        print((-1))

        exit()

    if surplus == 0:

        break

    checked[surplus] = True

    ans += 1



print(ans)



k = int(eval(input()))



surplus = 0

ans = 1

while 1:

    if ans > k:

        print((-1))

        exit()

    surplus = ((surplus * 10) + 7) % k

    if surplus == 0:

        break

    ans += 1

print(ans)



k = int(eval(input()))
checked = [False] * k
surplus = 0
ans = 1
while 1:
    surplus = ((surplus * 10) + 7) % k
    if checked[surplus]:
        print((-1))
        exit()
    if surplus == 0:
        break
    checked[surplus] = True
    ans += 1
print(ans)

k = int(eval(input()))
surplus = 0
ans = 1
while 1:
    if ans > k:
        print((-1))
        exit()
    surplus = ((surplus * 10) + 7) % k
    if surplus == 0:
        break
    ans += 1
print(ans)

-checked = [False] * k -    surplus = ((surplus * 10) + 7) % k -    if checked[surplus]: +    if ans > k: +    surplus = ((surplus * 10) + 7) % k -    checked[surplus] = True