N = int(input()) is_prime = [True for i in range(N+1)] is_prime[0] = is_prime[1] = False for i in range(2,N+1): if not is_prime[i]: continue for j in range(i*2,N+1,i): is_prime[j] = False prime = [i for i in range(2,N+1) if is_prime[i]] P = len(prime) dp = [0 for i in range(N+1)] dp[0] = 1 for i in range(P): for j in range(N,-1,-1): if dp[j] and j+prime[i] <= N: dp[j+prime[i]] = max(dp[j+prime[i]],dp[j]+1) print(dp[N]-1 if dp[N] != 0 else -1)