N=int(input()) if N==1: print(-1) exit() def eratosthenes(n): if n==2: return [2] prime = [2] limit = int(n**0.5) data = [i + 1 for i in range(2, n, 2)] while True: p = data[0]#まだ残ってる中での最小の素数 if limit <= p: return prime + data prime.append(p) data = [e for e in data if e % p != 0]#リスト内包表記で消してる prime=eratosthenes(N) dp=[-1]*(N+1) dp[0]=0 for i in prime: for j in reversed(range(N+1)): if dp[j]==-1: continue if j+i<=N: dp[j+i]=max(dp[j+i],dp[j]+1) print(dp[-1] if dp[-1]!=-1 else -1)