k = gets.to_i
x = 7
if k % 2 == 0 or k % 5 == 0
  puts "-1"
  exit
end

require "prime"
ps = Prime.prime_division k
qs = ps.map do |(q, e)|
  next 999982**e if q == 999983
  y = 7
  cnt = 1
  until y % q == 0
    cnt += 1
    y = y * 10 + 7
  end
  cnt ** e
end


p qs.inject(&:*)