N = int(input()) if N > 1: p = [2] for i in range(3,N+1,2): for s in p: if i%s == 0: break else: p += [i] else: print(-1) exit() p = p[::-1] Q = [0]*len(p) q = 0 i = len(p)-1 W = 0 while True: if i < 0: Q = [0] break elif q + p[i] == N: Q[i] = 1 if W < sum(Q): W = sum(Q) Q[i] = 0 d = Q.index(1) q -= p[d] Q[d] = 0 i = d-1 elif q + p[i] < N: Q[i] = 1 q += p[i] i -= 1 elif Q.count(1) == 0: break else: d = Q.index(1) q -= p[d] Q[d] = 0 i = d-1 print(W if W != 0 else -1)