import sys input = sys.stdin.readline import math def main(): n = int(input()) ans = n j = 1 while True: i = math.floor(n ** (1/j)) k = n - i ** j if k < 0: i -= 1 k = n - i ** j ans = min(ans, i+j+k) j += 1 #print(i,j,k) if i == 1: break print(ans) if __name__ == "__main__": main()