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