#include typedef long long ll; typedef unsigned long long ull; using namespace std; #define pb push_back int dy[]={0, 0, 1, -1, 1, 1, -1, -1}; int dx[]={1, -1, 0, 0, 1, -1, -1, 1}; #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define mp make_pair #define fi first #define sc second #define INF 1000000000 ll n; ll dp[3000][30000]; bool hurui[20001]; void gethurui(bool hurui[],ll n){ hurui[0] = hurui[1] = false; for(ll i = 2;i <= n;i++) hurui[i] = true; for(ll i = 2;i <= int(sqrt(n) + 0.1);i++){ if(!hurui[i]) continue; for(ll j = i * 2;j <= n;j += i) hurui[j] = false; } } vector< ll > p; int main(){ cin >> n; gethurui(hurui,n); REP(i,n + 1){ if(hurui[i]) p.pb(i); } ll ps = p.size(); REP(i,n + 1){ dp[0][i] = (i == p[0]) ? 1 : -INF; } dp[0][0] = 0; FOR(i,1,ps){ REP(j,n+1){ if(j < p[i]){ dp[i][j] = dp[i - 1][j]; continue; } dp[i][j] = max(dp[i - 1][j - p[i]] + 1,dp[i - 1][j]); } } cout << ((dp[ps - 1][n] > 0) ? dp[ps - 1][n] : -1) << endl; return 0; }