import sys input = sys.stdin.readline from collections import * 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 judge(x): res = 0 for i in range(k): res += pow(x, i) if res>N//d: return False return True def binary_search(): l, r = 2, 10**18 while l<=r: m = (l+r)//2 if judge(m): l = m+1 else: r = m-1 return r N = int(input()) if N<=2: print(2) exit() divs = make_divs(N) ans = N-1 for d in divs: for k in range(1, 40): p = binary_search() if p>d and (pow(p, k)-1)//(p-1)==N//d: ans = min(ans, p) print(ans)