#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include using namespace std; #include using namespace atcoder; #define REP(i, n) for(int i = 0; i < (int)n; i++) #define LREP(i, n) for(LL i = 0; i < (LL)n; i++) #define RREP(i, n) for(int i = (int)n-1; i >= 0; i--) #define V(T) vector #define P pair #define LP pair #define T3 tuple #define T4 tuple #define INF 1000000007 #define SIZE 500100 #define MOD 1000000007 typedef long long LL; LL N; bool check(LL p) { if (N < p) return true; LL n = N; LL d = N % p; bool res = true; while (n > 0) { if (n % p != d) res = false; n = (n - n % p); n /= p; } return res; } int main() { cin >> N; LL ans = N - 1; for (LL i = 2; i <= 1000000; i++) { if (check(i)) ans = min(ans, i); } for (LL i = 1; i * i <= N; i++) { if (N % i == 0) { LL j = N / i; LL p = j - 1; if (i < p) ans = min(ans, p); } } cout << ans << endl; }