def make_divisors(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] N = int(input()) dp = [1 << 60] * (N + 1) dp[1] = 0 for i in range(1, N + 1): for k in range(2, N + 1): if i * k > N: break dp[i * k] = min(dp[i * k], dp[i] + k) print(dp[N])