K = int(eval(input()))



flg = [False]*K



tmp = 7 % K

cnt = 1

if tmp == 0:

    print(cnt)

    exit()

while True:

    tmp = (tmp*10+7)%K

    if flg[tmp]:

        print((-1))

        break

    else:

        cnt += 1

        if tmp == 0:

            print(cnt)

            break

        flg[tmp] = True

K = int(eval(input()))

t = 7

t %= K



for i in range(K+1):

    if t == 0:

        print((i+1))

        exit()

    t = (t*10+7)%K

print((-1))

K = int(eval(input()))
flg = [False] * K
tmp = 7 % K
cnt = 1
if tmp == 0:
    print(cnt)
    exit()
while True:
    tmp = (tmp * 10 + 7) % K
    if flg[tmp]:
        print((-1))
        break
    else:
        cnt += 1
        if tmp == 0:
            print(cnt)
            break
        flg[tmp] = True

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

-flg = [False] * K -tmp = 7 % K -cnt = 1 -if tmp == 0: -    print(cnt) -    exit() -while True: -    tmp = (tmp * 10 + 7) % K -    if flg[tmp]: -        print((-1)) -        break -    else: -        cnt += 1 -        if tmp == 0: -            print(cnt) -            break -        flg[tmp] = True +t = 7 +t %= K +for i in range(K + 1): +    if t == 0: +        print((i + 1)) +        exit() +    t = (t * 10 + 7) % K +print((-1))