#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); ll N; cin >> N; ll ans = N - 1; // 1 <= d < p // dddddd = d(111111) = d(1+p+p^2+p^3+p^4+p^5) // N = d * (p^(keta) - 1) / (p - 1) vector div; for(ll i = 1; i * i <= N; i++) { if(N % i == 0) { div.push_back(i); if(i * i != N) div.push_back(N / i); } } for(ll d : div) { ll k = N / d; // (p^x - 1) / (p - 1) = N / d = k // p^x - 1 = kp - k // p(k - p^(x-1)) = k - 1 for(ll i = 1; i * i <= k - 1; i++) { if((k - 1) % i == 0) { ll p = i; if(2 <= p && d < p) { // k - p^(x-1) = (k - 1) / p = y ll y = (k - 1) / p; // p^(x-1) = k - y = z ll z = k - y; while(z % p == 0) z /= p; if(z == 1) { ans = min(ans, p); } } p = (k - 1) / i; if(2 <= p && d < p) { ll y = (k - 1) / p; // p^(x-1) = k - y = z ll z = k - y; while(z % p == 0) z /= p; if(z == 1) { ans = min(ans, p); } } } } } cout << ans << endl; }