import sys def make_divisors(n): divisors = [] i = 1 while i ** 2 <= n: if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) i += 1 divisors.sort() return divisors N = int(input()) if N == 1: print(2) sys.exit() if N == 2: print(3) sys.exit() D = make_divisors(N) D.pop(-1) ans = 10 ** 12 for a in D: n = N // a D2 = make_divisors(n-1) D2.remove(1) flag = 0 for p in D2: if a >= p: continue tmp = 1 p2 = 1 while tmp < n: if n - 1 == p * tmp: ans = min(p,ans) flag = 1 break p2 *= p tmp += p2 if flag == 1: break print(ans)