using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = long.Parse(ReadLine()); var sq = (int)Math.Ceiling(Math.Sqrt(n)) + 1; for (var i = 2L; i <= sq; ++i) { if (Check(n, i)) { WriteLine(i); return; } } for (var i = sq; i > 0; --i) { if (n % i == 0 && n / i > 2 && n / i - 1 > i) { WriteLine(n / i - 1); return; } } } static bool Check(long n, long p) { var list = new List(); while (n > 0) { list.Add(n % p); if (list.Count > 1 && list[^1] != list[^2]) return false; n /= p; } return true; } }