def fact(A): c0 = A r = 2 lis = [] count = 1 while A != 1: if A%r == 0: A = A//r lis.append(r) r = 2 else: r += 1 if r > int(pow(c0,0.5))+1: lis.append(A) break return(lis) L = [] n = int(input()) for i in range(2,n+1): s = fact(i) if len(s) == 1: L.append(i) d = [-1]*(n+1) d[0] = 0 for x in L: for i in range(n+1): j = n - i if x+j > n: pass elif d[j] != -1: d[j+x] = max(d[j+x], d[j]+1) print(d[-1])