N = int(input()) if N == 1: print(2) exit() P = [[1] * 45 for i in range(1000)] inf = 10 ** 18 for i in range(1000): for j in range(44): P[i][j + 1] = min(inf, P[i][j] * i) def f(p, d): if p >= 10 ** 9: return inf if p >= 10 ** 6 and d >= 3: return inf if p >= 10 ** 4 and d >= 4: 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)