import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); boolean[] isNotPrime = new boolean[n + 1]; TreeMap map = new TreeMap<>(); map.put(0, 0); for (int i = 2; i <= n; i++) { if (!isNotPrime[i]) { for (int j = 2; j * i <= n; j++) { isNotPrime[j * i] = true; } Integer x = n + 1; while ((x = map.lowerKey(x)) != null) { int value = map.get(x); if (x + i <= n && (!map.containsKey(x + i) || map.get(x + i) <= value)) { map.put(x + i, value + 1); } } } } if (!map.containsKey(n)) { System.out.println(-1); } else { System.out.println(map.get(n)); } } }