n = int(input()) ans = n for i in range(2, 10 ** 7): j = 0 while n - pow(i, j) > 0: ans = min(ans, i + j + (n - pow(i, j))) j += 1 print(ans)