import java.util.*; import java.io.InputStreamReader; import java.io.BufferedReader; import java.util.Arrays; import java.util.List; import java.util.ArrayList; import java.util.ArrayDeque; import java.util.Deque; import java.util.Collections; import java.awt.Point; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); List primeNums = new ArrayList(); boolean isPrime = true; for (int i = 2; i <= n; i++) { isPrime = true; for (int j = 2; j <= Math.sqrt(i); j++) { if (i % j == 0) { isPrime = false; } } if (isPrime) { //System.out.println(i); primeNums.add(i); } } //合計がiとなるときの和の回数の最大値 int[] dp = new int[n+1]; dp[0] = 0; for (int i = 1; i <= n; i++) { dp[i] = -1; } for (int p : primeNums) { for (int i = n; i >= 0; i--) { if (i+p <= n && dp[i] != -1) { dp[i+p] = Math.max(dp[i] + 1, dp[i+p]); //System.out.println("dp " + i + " =" + dp[i]); } } } System.out.println(dp[n]); } } class Box { int w; int h; public Box(int w, int h) { this.w = w; this.h = h; } } class BoxComparator1 implements Comparator{ public int compare(Box b1, Box b2) { return b1.w - b2.w; } } class BoxComparator2 implements Comparator { public int compare(Box b1, Box b2) { return b1.h - b2.h; } }