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()) from functools import lru_cache @lru_cache(maxsize=1000) def f(x): if x == 1: return 0 divs = make_divisors(x) best = 1 << 60 for d in divs: if d == 1: continue best = min(best, f(x // d) + d) return best print(f(N))