n = int(input()) ans = n i = 2 while i <= 10**6: j = 1 while 1: if i**j > n: j -= 1 break j += 1 ans = min(ans, i+j+(n-i**j)) i += 1 print(ans)