K = int(input())
verbose = False

path = set()
a = 0
step = 0
while True:
    step += 1
    a = (a*10 + 7) % K
    if verbose: print (step, ':', a)
    if a == 0:
        print (step)
        break
    if a in path:
        print ('-1')
        break
    path.add(a) K = int(input()) K int(input()) int input() input verbose = False verbose False path = set() path set() set a = 0 a 0 step = 0 step 0 while True:
    step += 1
    a = (a*10 + 7) % K
    if verbose: print (step, ':', a)
    if a == 0:
        print (step)
        break
    if a in path:
        print ('-1')
        break
    path.add(a) True step += 1 step 1 a = (a*10 + 7) % K a (a*10 + 7) % K a*10 + 7 a*10 a 10 7 K if verbose: print (step, ':', a)
     verbose if a == 0:
        print (step)
        break
     a == 0 a 0 print (step) print step break if a in path:
        print ('-1')
        break
     a in path a path print ('-1') print '-1' break path.add(a) path.add path add a K = int(input()) int(input()) K a = 0 0 a step = 0 0 step path = set() set() path verbose = False False verbose step += 1 1 step a = (a*10 + 7) % K (a*10 + 7) % K a
K = int(input())
verbose = False

path = set()
a = 0
step = 0
while True:
    step += 1
    a = (a*10 + 7) % K
    if verbose: print (step, ':', a)
    if a == 0:
        print (step)
        break
    if a in path:
        print ('-1')
        break
    path.add(a)
