#include using namespace std; #define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i)) using ll = long long; using P = pair; using namespace std; template void vin(vector& v, int n) { v.resize(n); for (int i = 0; i < n; ++i) { cin >> v[i]; } } int N; int p; int prime[20101]; int not_prime[20101]; int eratos(int n) { int p = 0; not_prime[0] = not_prime[1] = true; for (int i=2; i<=n; ++i) { if (!not_prime[i]) { prime[p++] = i; for (int j=2*i; j<=n; j+=i) not_prime[j] = true; } } return p; } int dp[20000][20000]; int solve(int i, int sum) { int& res = dp[i][sum]; if (~res) return res; if (sum == N) { res = 0; } else if (i >= p or sum + prime[i] > N) { res = -1e8; } else { res = max(solve(i+1, sum), solve(i+1, sum+prime[i]) + 1); } return res; } int main() { cin >> N; p = eratos(20000); sort(prime, prime+p); fill(dp[0], dp[p+10], -1); int tmp = solve(0, 0); cout << (tmp <= 0 ? -1 : tmp) << endl; return 0; }