N = int(input()) if N == 1: print(2) exit() if N == 2: print(3) exit() inf = 10 ** 12 def f(v, p, d): val = 1 for i in range(d - 1): val *= p val += 1 if v * val >= inf: return v * val return v * val ans = N - 1 for d in range(2, 45): for v in range(1, 10**18): if f(v, v + 1, d) > N: break yes = v + 1 no = ans if no <= yes: break while no - yes != 1: mid = (yes + no)//2 if f(v, mid, d) <= N: yes = mid else: no = mid if f(v, yes, d) == N: ans = min(ans, yes) print(ans)