def primes(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return [i for i in range(n + 1) if is_prime[i]] N = int(input()) l = primes(N) dp = [ [ 0 for j in range(N+1)] for i in range(len(l)+1)] t = 0 for i in range(len(l)): t += l[i] for j in range(min(N+1,t+1)): if j - l[i] >= 0: dp[i+1][j] = max(dp[i][j] , dp[i][j-l[i]]+ 1) else: dp[i+1][j] = dp[i][j] ans = 0 for i in range(len(l)+1): ans = max(ans , dp[i][N]) if ans == 0: print(-1) else: print(ans)