import java.util.Scanner; class Sample{ public static boolean is_prime(int n, int []primes, int num_primes){ for (int i = 0; i < num_primes; i++) { int prime = primes[i]; if (n%prime == 0){ return false; } } return true; } public static boolean is_in_keys(int x, int []keys, int num_keys){ for (int i = 0; i < num_keys; i++) { if (x == keys[i]){ return true; } } return false; } public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int num_primes = 1; int primes[] = new int[n]; int sum_primes[] = new int[n]; int _sum = 2; primes[0] = 2; sum_primes[0] = 2; for (int i = 3; i < n+1; i++) { if (is_prime(i, primes, num_primes)){ _sum += i; primes[num_primes] = i; sum_primes[num_primes] = _sum; num_primes += 1; } } int data[] = new int[n+1]; for (int i = 0; i < n+1; i++) { data[i] = -1; } int keys[] = new int[n+1]; int num_keys = 0; for (int i = num_primes-1; i > -1; i--) { int prime = primes[i]; //System.out.println("prime" + prime); //System.out.println(data[8]); _sum = sum_primes[i]; if (!is_in_keys(prime, keys, num_keys)){ data[prime] = 1; keys[num_keys] = prime; num_keys += 1; } for (int j = 0; j < num_keys-1; j++) { int key = keys[j]; if (!(key+prime > n) && (!(key+_sum < n))){ //.out.println(key+prime); if (!is_in_keys(key+prime, keys, num_keys)){ data[key+prime] = data[key] + 1; keys[num_keys] = key+prime; num_keys += 1; } else{ if (data[key+prime] < data[key] + 1){ data[key+prime] = data[key] + 1; } } } } } System.out.println(data[n]); } }