#include <bits/stdc++.h>
using namespace std;

int main() {
    int64_t n;
    cin >> n;
    if (n <= 2) {
        cout << n + 1 << endl;
        return 0;
    }
    for (int64_t p = 2; p * p <= n; p++) {
        int64_t s = 1;
        while (s * p + 1 <= n) {
            s = s * p + 1;
        }
        if (n % s == 0 and n / s * p > n) {
            cout << p << endl;
            return 0;
        }
    }
    int64_t ans = n - 1;
    for (int64_t d = 1; d * d <= n; d++) {
        if (n % d == 0 and n / d * (n / d - 1) > n) {
            ans = n / d - 1;
        }
    }
    cout << ans << endl;
}