n = int(input()) if n == 1: print(2) exit() if n == 2: print(3) exit() ans = n - 1 for k in range(1, n+10): if k ** 2 > n: break if n % k: continue for j in range(1, n): p = (n - k) // j if p <= k: break if (n - k) % j: continue tmp = n flg = 1 while tmp: if tmp % p != k: flg = 0 break tmp //= p if flg: ans = min(ans, p) print(ans)