require "prime"
k = gets.chomp.to_i
arr = Array.new(k + 1, true)

ngo = 1
1.upto(18) do |i|
	np = Prime.prime_division(ngo)

	np.each do |n|
		nn = n[0]
		next if nn > k || !arr[nn]
		while nn <= k
			arr[nn] = false
			nn += n[0]
		end
	end
	ngo = ngo * 10 + 1
end

if !arr[k]
	ngo = 7
	1.upto(10**9) do |i|
		if ngo % k == 0
			puts i
			#puts "jf;a"
			exit
		end
		#puts "mod:#{ngo%k} ngo:#{ngo}"
		ngo = ngo * 10 + 7
	end
end

if Prime.prime?(k) && k >= 11
	puts k-1
else
	-1
end