n=int(input()) ans=[] for i in range(1,200000): for j in range(1,50): if pow(i,j)>n: break k=n-pow(i,j) ans.append((i+j+k,i,j,k)) ans.sort() print(ans[0][0])