#include using namespace std; #if __has_include() #include using namespace atcoder; #endif using ll = long long; using ld = long double; #define all(s) (s).begin(),(s).end() #define rep2(i, m, n) for (int i = (m); i < (n); ++i) #define rep(i, n) rep2(i, 0, n) #define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i) #define drep(i, n) drep2(i, n, 0) #define rever(vec) reverse(vec.begin(), vec.end()) #define sor(vec) sort(vec.begin(), vec.end()) #define fi first #define se second #define P pair const ll mod = 998244353; //const ll mod = 1000000007; const ll inf = 2000000000000000000ll; static const long double pi = 3.141592653589793; void vcin(vector &n){for(int i=0;i>n[i];} void vcout(vector &n){for(int i=0;i void chmax(T& t,const U& u){if(t void chmin(T& t,const U& u){if(t>u) t=u;} ll modPow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; } bool check(ll a,ll p){ ll tmp=a%p; while(a){ if(a%p!=tmp){ return false; } a/=p; } return true; } int main() { /* mod は 1e9+7 */ ios::sync_with_stdio(false); std::cin.tie(nullptr); cout<< fixed << setprecision(10); ll a; cin>>a; ll ans=a-1; for(ll i=1;i*i<=a;i++){ if(a%i==0){ ll x=i; for(ll j=1;j*j<=a/i-1;j++){ if((a/i-1)%j==0){ if(j>=2&&check(a,j)){ chmin(ans,j); } if((a/i-1)/j>=2&&check(a,(a/i-1)/j)){ chmin(ans,(a/i-1)/j); } } } for(ll j=1;j*j<=a/(a/i)-1;j++){ if((a/(a/i)-1)%j==0){ if(j>=2&&check(a,j)){ chmin(ans,j); } if((a/(a/i)-1)/j>=2&&check(a,(a/(a/i)-1)/j)){ chmin(ans,(a/(a/i)-1)/j); } } } } } cout<