import logging import sys from inspect import currentframe sys.setrecursionlimit(10 ** 6) input = sys.stdin.readline logging.basicConfig(level=logging.DEBUG) def sieve_eratosthenes(n): is_prime = [True] * (n + 1) is_prime[0] = is_prime[1] = False for i in range(2, n + 1): for j in range(2 * i, n + 1, i): is_prime[j] = False return is_prime def dbg(*args): id2names = {id(v): k for k, v in currentframe().f_back.f_locals.items()} logging.debug( ", ".join(id2names.get(id(arg), "???") + " = " + repr(arg) for arg in args) ) def main(): # 素数iを足す遷移を後ろから後ろから行う n = int(input()) table = sieve_eratosthenes(n) dp = [-1] * (n + 1) # for i, fl in enumerate(table): # if fl: # dp[i] = 1 dp[0] = 0 for i, fl in enumerate(table): if fl: # for j in range(n, i, -1): for j in range(n, -1, -1): if dp[j] != -1 and j + i <= n: dp[i + j] = max(dp[i + j], dp[j] + 1) # ans = max(dp) dbg(table) dbg(dp) ans = dp[n] print(ans) if __name__ == "__main__": main()