import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayList primes = new ArrayList<>(); int[] counts = new int[n + 1]; Arrays.fill(counts, -1); counts[0] = 0; for (int i = 2; i <= n; i++) { if (isPrime(i, primes)) { primes.add(i); for (int j = n - i; j >= 0; j--) { if (counts[j] < 0) { continue; } counts[j + i] = Math.max(counts[j + i], counts[j] + 1); } } } if (counts[n] > 0) { System.out.println(counts[n]); } else { System.out.println(-1); } } static boolean isPrime(int x, ArrayList primes) { for (int y : primes) { if (y * y > x) { break; } if (x % y == 0) { return false; } } return true; } }