default = -100000 n = int(input()) primes = [100000] lst = [0 if (i == 0 or i == 1) else 1 for i in range(n + 1)] for i in range(n + 1): if lst[i]: primes.append(i) for j in range(i * 2,n + 1,i): lst[j] = 0 dp = [[1 if i == primes[j] else default for j in range(len(primes))] for i in range(n + 1)] for i in range(2,n + 1): for j in range(1,len(primes)): if i == 0 or i == 1 or j == 0: dp[i][j] = 0 elif i >= primes[j]: dp[i][j] = max(dp[i][j],dp[i][j - 1], dp[i - primes[j]][j - 1] + 1) else: dp[i][j] = dp[i][j - 1] if dp[n][len(primes) - 1] < 0: print(-1) else: print(dp[n][len(primes) - 1])