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