import sys input = sys.stdin.readline # "\n"を含む def solve(n): # j = 0 -> i+j+k = n-1 # j = 1 -> i+j+k = n+1 res = 0 for j in range(2, 1<<10): # i = 0 -> i+j+k = n-1 # i = 1 -> i+j+k = n i = 2 while n - i**j >= 0: i += 1 if i == 2: break i -= 1 res = max(res, i**j - i - j) if res <= 1: return n - 1 else: return n - res def main(): n = int(input()) res = solve(n) print(res) if __name__ == "__main__": main()