K = int(input())
dic = {}
x = 0
count = 0
while 1:
    x = (x * 10 + 7) % K
    count += 1
    if x == 0:
        print(count)
        exit()
    if x in dic:
        print(-1)
        exit()
    dic[x] = 1 K = int(input()) K int(input()) int input() input dic = {} dic {} x = 0 x 0 count = 0 count 0 while 1:
    x = (x * 10 + 7) % K
    count += 1
    if x == 0:
        print(count)
        exit()
    if x in dic:
        print(-1)
        exit()
    dic[x] = 1 1 x = (x * 10 + 7) % K x (x * 10 + 7) % K x * 10 + 7 x * 10 x 10 7 K count += 1 count 1 if x == 0:
        print(count)
        exit()
     x == 0 x 0 print(count) print count exit() exit if x in dic:
        print(-1)
        exit()
     x in dic x dic print(-1) print -1 exit() exit dic[x] = 1 dic[x] dic x 1 dic = {} {} dic count = 0 0 count x = 0 0 x count += 1 1 count x = (x * 10 + 7) % K (x * 10 + 7) % K x K = int(input()) int(input()) K
K = int(input())
dic = {}
x = 0
count = 0
while 1:
    x = (x * 10 + 7) % K
    count += 1
    if x == 0:
        print(count)
        exit()
    if x in dic:
        print(-1)
        exit()
    dic[x] = 1
