#include using namespace std; using ll = __int128_t; istream& operator>>(istream& is, ll& v) { string s; is >> s; v = 0; for (int i = 0; i < (int)s.size(); i++) { if (isdigit(s[i])) { v = v * 10 + s[i] - '0'; } } if (s[0] == '-') { v *= -1; } return is; } ostream& operator<<(ostream& os, const ll& v) { if (v == 0) { return (os << "0"); } __int128_t num = v; if (v < 0) { os << '-'; num = -num; } string s; for (; num > 0; num /= 10) { s.push_back((char)(num % 10) + '0'); } reverse(s.begin(), s.end()); return (os << s); } ll mul(const ll a, const ll b, const ll mod) { if (b == 0) { return 0; } if (b % 2 == 1) { return (mul(a, b - 1, mod) + a) % mod; } else { const ll pp = mul(a, b / 2, mod); return (pp + pp) % mod; } } ll power(const ll a, const ll n, const ll mod) { if (n == 0) { return 1; } if (n % 2 == 1) { return mul(power(a, n - 1, mod), a, mod); } else { const ll aa = power(a, n / 2, mod); return mul(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{}()}; for (int i = 0; i < TEST; i++) { const ll a = mt() % (n - 1); if (power(a, n - 1, n) != 1) { return false; } ll num = power(a, d, n); if (num != 1) { bool comp = true; for (ll r = 0; r < s; r++) { if (num == n - 1) { comp = false; break; } num = mul(num, num, n); } if (comp) return false; } } return true; } int main() { ll N; cin >> N; cout << (N >= 26 ? N % 8 == 1 and MillerRabin(N - 8) ? 14 : 8 : N == 9 ? 7 : N == 10 ? 7 : N == 15 ? 7 : N == 16 ? 7 : N == 18 ? 8 : N == 21 ? 19 : N == 22 ? 7 : N == 25 ? 23 : N - 1) << endl; return 0; }