#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; } 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 { return mul(2 * a % mod, b / 2, 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 { return power(mul(a, a, mod), n / 2, mod); } } bool MillerRabin(const ll n) { if (n == 1) { return false; } constexpr int TEST = 100; ll s = 0, d = n - 1; for (; (d & 1) == 0; s++, d >>= 2) {} static mt19937 mt{random_device{}()}; for (int i = 0; i < TEST; i++) { const ll a = (mt() % (n - 2)) + 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 : (int)N - 1) << endl; return 0; }