# https://atcoder.jp/contests/abc174/tasks/abc174_c

K = gets.to_i

K /= 7 if (K % 7).zero?

if K.even? || (K % 5).zero?
  puts(-1)
  exit 0
end

ws = 10.times.map { |i| K * i }
n = m = 1
v = 1

K.times do
  # p [n, m, v]
  w = ws.find { |a| a % 10 == v % 10 }
  while v < w
    v += 10**m
    n += 1
    m += 1
    # p [' ', n, m, v]
  end
  v -= w
  if v.zero?
    puts n
    exit 0
  end
  v /= 10
  m -= 1
end

puts(-1)
