import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np N = int(read()) def make_prime(U): is_prime = np.zeros(U,np.bool_) is_prime[2] = 1 is_prime[3::2] = 1 M = int(U**.5)+1 for p in range(3,M,2): if is_prime[p]: is_prime[p*p::p+p] = 0 return is_prime, is_prime.nonzero()[0] U = 20000 _, primes = make_prime(U) INF = 10 ** 5 dp = np.full(U+1,-INF,np.int32) dp[0] = 0 for p in primes: np.maximum(dp[p:], dp[:-p] + 1, out = dp[p:]) answer = dp[N] if answer < 0: answer = -1 print(answer)