#include using namespace std; int main() { ios::sync_with_stdio(false); int64_t N; { cin >> N; } for (int i = 2; (int64_t) i * i <= N; ++i) { int64_t n = N; int h = n % i; bool ok = true; for (; n; n /= i) ok &= h == n % i; if (ok) { cout << i << endl; return 0; } if (N % i == 0 && N / i < i - 1) { cout << i << endl; return 0; } } cout << N - 1 << endl; }