#include #define rep(i,n) for(ll i = 0; i < (n); ++i) #define srep(i,s,t) for (ll i = s; i < t; ++i) #define drep(i,n) for(ll i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair P; #define yn {puts("YES");}else{puts("NO");} #define MAX_N 200005 int main() { ll n; cin >> n; if(n == 1){ cout << 2 << endl; return 0; } if(n == 2){ cout << 3 << endl; return 0; } ll ans = n - 1; srep(i,2,1001001){ if(i >= ans) break; ll nn = n; ll val = -1; int ok = 1; while(nn > 0){ ll x = nn % i; nn /= i; if(val == -1){ val = x; }else{ if(x != val){ ok = 0; break; } } } if(ok) ans = i; } srep(i,1,1001001){ if(i>=n) break; if((n-i)%i == 0 && (n-i)/i > i){ ans = min(ans, (n-i)/i); } } cout << ans << endl; return 0; }