k = int(eval(input()))

x = 7%k

s = set()

#i = 1

#while len(s) == 0:

for i in range(1, k+1):

  if x == 0:

    print(i)

    exit()

  #s.add(x)

  x = (x*10+7)%k

  #i += 1

print((-1))

k = int(eval(input()))

x = 7%k

for i in range(1, k+1):

  if x == 0:

    print(i)

    exit()

  x = (x*10+7)%k

print((-1))

k = int(eval(input()))
x = 7 % k
s = set()
# i = 1
# while len(s) == 0:
for i in range(1, k + 1):
    if x == 0:
        print(i)
        exit()
    # s.add(x)
    x = (x * 10 + 7) % k
    # i += 1
print((-1))

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

-s = set() -# i = 1 -# while len(s) == 0: -    # s.add(x) -    # i += 1