require 'prime' n = gets.chomp.to_i #素数を固定して回す max = 20001 dp = Array.new(max,0) a = Prime.each(max).to_a.reverse.map(&:to_i) a.each do |i| dp[i] += 1 end a.each do |i| (max-1-i).downto(i+1) do |j| if dp[j] > 0 dp[i+j] = [dp[j]+1,dp[i+j]].max end end end if dp[n] == 0 puts "-1" else puts dp[n] end