#include using namespace std; using LL=long long; using ULL=unsigned long long; #define rep(i,n) for(int i=0;i<(n);i++) int main(){ LL N; cin>>N; LL ans=N-1; for(LL i=2; i*i<=N; i++){ if(N%i==0) if((N/i-1)>i) ans=min(ans,N/i-1); } for(LL i=2; i*i<=N; i++){ LL x=1; while(x*i+1<=N) x=x*i+1; if(N%x!=0) continue; if(N/x>=i) continue; ans=min(ans,i); } cout<