k = int(input())
d1 = k % 10
mae = 0
sd = [0]*10
cnt = 0
if not d1 in (1, 3, 7, 9):
  print(-1)
  exit()
for i in range(1,10) :
  sd[d1 * i % 10] = i
#print(sd)

for j in range(999999):
  d2 = 7 - mae % 10
  s = str(sd[d2] * k + mae)
#  print("mae ", mae,"",sd[d2] * k )
#  print("s1=",s)
  for i in range(len(s)-1, -1, -1):
#    print("s[",i,"]=",s[i])
    if (s[i]) == "7":
      cnt += 1
    else:
      s = s[0:i+1]
      mae = int(s)
#      print("s2=",s)
      break
#    print("i= ",i)
    if i == 0 :
      print(cnt)
      exit() k = int(input()) k int(input()) int input() input d1 = k % 10 d1 k % 10 k 10 mae = 0 mae 0 sd = [0]*10 sd [0]*10 [0] 0 10 cnt = 0 cnt 0 if not d1 in (1, 3, 7, 9):
  print(-1)
  exit() not d1 in (1, 3, 7, 9) d1 in (1, 3, 7, 9) d1 (1, 3, 7, 9) 1 3 7 9 print(-1) print -1 exit() exit for i in range(1,10) :
  sd[d1 * i % 10] = i
#print(sd) i range(1,10) range 1 10 sd[d1 * i % 10] = i sd[d1 * i % 10] sd d1 * i % 10 d1 * i d1 i 10 i for j in range(999999):
  d2 = 7 - mae % 10
  s = str(sd[d2] * k + mae)
#  print("mae ", mae,"",sd[d2] * k )
#  print("s1=",s)
  for i in range(len(s)-1, -1, -1):
#    print("s[",i,"]=",s[i])
    if (s[i]) == "7":
      cnt += 1
    else:
      s = s[0:i+1]
      mae = int(s)
#      print("s2=",s)
      break
#    print("i= ",i)
    if i == 0 :
      print(cnt)
      exit() j range(999999) range 999999 d2 = 7 - mae % 10 d2 7 - mae % 10 7 mae % 10 mae 10 s = str(sd[d2] * k + mae) s str(sd[d2] * k + mae) str sd[d2] * k + mae sd[d2] * k sd[d2] sd d2 k mae for i in range(len(s)-1, -1, -1):
#    print("s[",i,"]=",s[i])
    if (s[i]) == "7":
      cnt += 1
    else:
      s = s[0:i+1]
      mae = int(s)
#      print("s2=",s)
      break
#    print("i= ",i)
    if i == 0 :
      print(cnt)
      exit() i range(len(s)-1, -1, -1) range len(s)-1 len(s) len s 1 -1 -1 if (s[i]) == "7":
      cnt += 1
    else:
      s = s[0:i+1]
      mae = int(s)
#      print("s2=",s)
      break
#    print("i= ",i)
     (s[i]) == "7" s[i] s i "7" cnt += 1 cnt 1 s = s[0:i+1] s s[0:i+1] s 0:i+1 0 i+1 i 1 mae = int(s) mae int(s) int s break if i == 0 :
      print(cnt)
      exit() i == 0 i 0 print(cnt) print cnt exit() exit mae = int(s) int(s) mae cnt = 0 0 cnt d2 = 7 - mae % 10 7 - mae % 10 d2 k = int(input()) int(input()) k s = str(sd[d2] * k + mae) str(sd[d2] * k + mae) s d1 = k % 10 k % 10 d1 s = s[0:i+1] s[0:i+1] s sd = [0]*10 [0]*10 sd cnt += 1 1 cnt mae = 0 0 mae
k = int(input())
d1 = k % 10
mae = 0
sd = [0]*10
cnt = 0
if not d1 in (1, 3, 7, 9):
  print(-1)
  exit()
for i in range(1,10) :
  sd[d1 * i % 10] = i
#print(sd)

for j in range(999999):
  d2 = 7 - mae % 10
  s = str(sd[d2] * k + mae)
#  print("mae ", mae,"",sd[d2] * k )
#  print("s1=",s)
  for i in range(len(s)-1, -1, -1):
#    print("s[",i,"]=",s[i])
    if (s[i]) == "7":
      cnt += 1
    else:
      s = s[0:i+1]
      mae = int(s)
#      print("s2=",s)
      break
#    print("i= ",i)
    if i == 0 :
      print(cnt)
      exit()