using System; class I { static void Main() => Console.WriteLine(Solve()); static object Solve() { var n = long.Parse(Console.ReadLine()); if (n <= 2) return n + 1; for (long p = 2; p * p <= n + 1; p++) { for (long d = p; d <= p * (n + 1); d *= p) { var q = (d - 1) / (p - 1); if (n % q == 0 && 0 < n / q && n / q < p) return p; } } return n - 1; } }