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; var r = long.MaxValue; for (long p = 2; p * p <= n + 1; p++) { // 3桁以上 for (long d = p * p * 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; } // 2桁 if (n % p == 0) { var q = n / p - 1; if (p < q) r = Math.Min(r, q); } } return r == long.MaxValue ? n - 1 : r; } }