def primes(n): is_p = [True for i in range(n+1)] i = 2 while i * i <= n: if is_p[i]: for j in range(i*i,n+1,i): is_p[j] = False i += 1 return [i for i in range(2,n+1) if is_p[i]] n = int(input()) p = primes(n) mp = {0:0} for i in range(len(p)): tmp = {} for x in mp: if x + p[i] > n: break tmp[x+p[i]] = max(mp[x]+1,mp[x+p[i]] if x+p[i] in mp else -1) mp.update(tmp) print(mp[n] if n in mp else -1)