import sys input = sys.stdin.readline n=int(input()) ANS=n for i in range(2,10**6): for j in range(100): if i**j>n: break else: ANS=min(ANS,i+j+n-i**j) print(ANS)