#region Header #!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools from queue import PriorityQueue import bisect import heapq def input(): return sys.stdin.readline()[:-1] sys.setrecursionlimit(1000000) #endregion # _INPUT = """3344 # """ # sys.stdin = io.StringIO(_INPUT) def get_primes(N): a = [True] * (N + 1) l = [] for n in range(2, N + 1): if a[n]: l.append(n) for i in range(n+n, N + 1, n): a[i] = False return l def main(): N = int(input()) primes = get_primes(N) T = [0 for _ in range(N+1)] for p in primes: T[p] = max(T[p], 1) for i in reversed(range(2, N+1)): if i == p and T[i] == 1: continue if T[i] > 0 and i+p <= N: T[i+p] = max(T[i+p], T[i] + 1) if T[N] > 0: print(T[N]) else: print(-1) if __name__ == '__main__': main()