N=int(input()) if N==1: print(-1) else: S=[1 for i in range(N+1)] S[0]=0 S[1]=0 for i in range(2,N+1): if S[i]==1: for j in range(2,N+1): if i*j>N: break else: S[i*j]=0 #print(S[:100]) s=[0] for i in range(len(S)): if S[i]==1: s.append(i) #print(s[:100]) dp=[[[0,0] for i in range(N+1)]for j in range(len(s))] ans=(-1) for i in range(1,len(s)): for j in range(1,N+1): if j-s[i]<0: dp[i][j][0]=dp[i-1][j][0] dp[i][j][1]=dp[i-1][j][1] else: dp[i][j][0]=max(dp[i-1][j][0],dp[i-1][j-s[i]][0]+s[i]) if dp[i][j][0]==dp[i-1][j][0]: dp[i][j][1]=dp[i-1][j][1] else: dp[i][j][1]=dp[i-1][j-s[i]][1]+1 if dp[i][j][0]==N: if dp[i][j][1]>ans: ans=dp[i][j][1] print(ans)