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