n = int(input()) res = n for i in range(1, 1000000): for j in range(1, 1000): if i ** j > n: break res = min(res, i + j + n - i ** j) print(res)