import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); boolean [] b = new boolean [N+1]; ArrayList prime = new ArrayList(); prime.add(2); for(int i=3; i<=N; i+=2){ if(b[i]==false){ prime.add(i); int k=2; while(i*k<=N){ b[i*k]=true; k++; } } } boolean [] dp = new boolean [N+1]; dp[0]=true; int [] num = new int [N+1]; for(int i=0; i=0; j--){ if(dp[j]){ int tmp=j+t; if(tmp<=N){ dp[tmp]=true; num[tmp]=Math.max(num[tmp],num[j]+1); } } } } int ans=num[N]; if(ans==0)ans=-1; System.out.println(ans); } }