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 while True: if i >= 0: if q + p[i] == N: Q[i] = 1 break 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 else: Q = [0] break print(sum(Q) if sum(Q) != 0 else -1)