n = int(input()) a = float("inf") dp = [a] * (n+2) dp[1] = 0 for i in range(1, n+2): for k in range(1, n+2): if i * k > n: break else: dp[i * k] = min(dp[i] + k, dp[i * k]) print(dp[n])