#include using namespace std; int main() { long long n; cin >> n; if (n == 1) { cout << 2 << endl; return 0; } long long ans = n-1; for (long long p = 2; p * p + p + 1 <= n; p++) { for (long long q = 1; q <= n; q = q * p + 1) { if (n % q == 0 && n / q < p) { ans = min(ans, p); break; } } } for (long long d = 1; d * (1 + d) < n; d++) { if (n % (1 + d) == 0 && n / (1 + d) < d) ans = min(ans, d); } cout << ans << endl; }