require "prime"
k = gets.chomp.to_i
hash = {}
hash[1] = true
ngo = 7
1.upto(17) do
	#print ngo
#	print " "
	pr = Prime.prime_division(ngo)
	pr.each do |rr|
		hash[rr[0]] = true
	end
	ngo = ngo * 10 + 7
end

kp = Prime.prime_division(k)
flag = true
kp.each do |kpp|
	kpp.each do |kppp|
		if !hash.has_key?(kppp)
			flag = false
		end
	end
end

if flag
	ngo = 7
	1.upto(20) do |i|
		if ngo % k == 0
			puts i 
			exit
		end
		ngo = ngo * 10 + 7
	end
end

if Prime.prime?(k) && k != 2
	puts k -1
else
	puts -1
end
