using System; using System.Collections.Generic; using System.Linq; using static Input; public class Prog { public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static void Solve() { int N = NextInt(); bool[] memo = Enumerable.Repeat(true, N + 1).ToArray(); List fact = new List(); for (int x = 2; x <= N; x++) { if (memo[x]) fact.Add(x); else continue; for (int t = 2; t * x <= N; t++) memo[t * x] = false; } int[] dp = Enumerable.Repeat(-INF, N + 1).ToArray(); dp[0] = 0; foreach (var e in fact) for (int x = N - e; x >= 0; x--) dp[x + e] = Math.Max(dp[x + e], dp[x] + 1); Console.WriteLine(dp[N] > 0 ? dp[N] : -1); } public static void Main() { var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue q = new Queue(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } public long Abs(long a, long b) => Math.Abs(a - b); }