import sys input = sys.stdin.readline def make_divs(n): divs = [] for i in range(1, int(n**0.5)+1): if n%i==0: divs.append(i) if i!=n//i: divs.append(n//i) return divs def binary_search(): l, r = 2, 10**12+10 while l<=r: m = (l+r)//2 if (pow(m, k)-1)//(m-1)<=N//d: l = m+1 else: r = m-1 return r N = int(input()) if N==1: print(2) exit() if N==2: print(3) exit() divs = make_divs(N) ans = N-1 for d in divs: for k in range(1, 41): p = binary_search() if p>d and (pow(p, k)-1)//(p-1)==N//d: ans = min(ans, p) print(ans)