from math import sqrt, ceil N = int(input()) def era_prime(N): temp = [True for _ in range(N+1)] temp[0] = temp[1] = False key = ceil(sqrt(N+1)) for i in range(2, key): if temp[i]: for k in range(i+i, N+1, i): temp[k] = False primes = [index for index, is_prime in enumerate(temp) if is_prime] return primes primes = era_prime(N) data = dict() keys = list() for prime in primes: if prime > 480: break new_keys = list() for key in [x for x in keys if x+prime < N + 1][::-1]: if key+prime not in data: data[key+prime] = data[key] + 1 new_keys.append(key+prime) else: data[key+prime] = max(data[key+prime], data[key]+1) if prime not in data: data[prime] = 1 new_keys.append(prime) keys += new_keys if N in data: print(data[N]) else: print(-1)