N = int(input()) if N == 1: print(2) exit() def f(p, d): 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 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)