#include using namespace std; using ll = long long; ll power(const ll a, const ll n, const ll mod = -1) { if (n == 0) { return 1; } if (n % 2 == 1) { return ((__int128_t)(1) * power(a, n - 1, mod) * a) % mod; } else { const ll aa = power(a, n / 2, mod); return ((__int128_t)(1) * aa * aa) % mod; } } bool MillerRabin(const ll n) { if (n == 1) { return false; } constexpr int TEST = 1000; ll s = 0, d = n - 1; for (; d % 2 == 0; s++, d /= 2) {} static mt19937 mt{random_device{}()}; uniform_int_distribution dist{1, n - 1}; for (int i = 0; i < TEST; i++) { const ll a = dist(mt); if (power(a, n - 1, n) != 1) { return false; } ll num = power(a, d, n); if (num != 1) { for (ll r = 0; r < s; r++) { if (num == n - 1) { return false; } num = ((__int128_t)(1) * num * num) % n; } } } return true; } int main() { ll N; cin >> N; cout << (N >= 26 ? MillerRabin(N - 8) ? 14 : 8 : N == 9 ? 7 : N == 10 ? 7 : N == 15 ? 7 : N == 16 ? 7 : N == 21 ? 19 : N == 22 ? 7 : N == 25 ? 23 : N - 1) << endl; return 0; }