memo = {} def dfs(i): if i==1:return 0 dmin = 10**6 for j in range(1,i+1): if j*j>i:break if i%j==0: if j not in memo: memo[j] = dfs(j) dmin = min(dmin,memo[j]+i//j) if j!=1: if i//j not in memo: memo[i//j] = dfs(i//j) dmin = min(dmin,memo[i//j]+j) return dmin print(dfs(int(input())))