n = int(input()) h_k = 10 ** 18 ans = 10 ** 20 for i in range(1,10 ** 6): if i == 1: j = 0 k = n-1 else: j = -1 while i ** (j+1) < n: k = n - i ** (j+1) j += 1 # if k >= h_k: # break # else: ans = min(i+j+k,ans) print(ans)