n = int(input()) ans = n # i == 1 for i in range(2, 10**6): j = 0 while i**(j + 1) <= n: j += 1 k = n - i**j ans = min(ans, i + j + k) print(ans)