#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) #define all(c) (c).begin(), (c).end() #define zero(a) memset(a, 0, sizeof a) #define minus(a) memset(a, -1, sizeof a) #define minimize(a, x) a = std::min(a, x) #define maximize(a, x) a = std::max(a, x) typedef __int128_t ll; int const inf = 1<<29; namespace math { ll mulmod(ll a, ll b, ll mod) { ll x = 0, y = a % mod; while(b > 0) { if(b & 1) { x = (x + y) % mod; } y = (y * 2) % mod; b /= 2; } return x % mod; } } namespace math { ll modular_exp(ll base, ll exp, ll mod) { ll x = 1; ll y = base; while(exp > 0) { if(exp & 1) { x *= y; x %= mod; } y *= y; y %= mod; exp >>= 1; } return x % mod; } } struct xor128 { unsigned x,y,z,w; xor128(): x(89165727), y(157892372), z(7777777), w(757328) {} unsigned next() { unsigned t=x^(x<<11); x=y;y=z;z=w; return w=w^(w>>19)^t^(t>>8); } unsigned next(unsigned k) { return next()%k; } } rndgen; namespace math { namespace prime { bool miller_rabin(ll p, int iteration) { if(p < 2) { return false; } if(p != 2 && p & 1) { return false; } ll s = p - 1; while(s & 1) { s >>= 1; } rep(_, iteration) { ll a = rndgen.next(p - 1) + 1; ll temp = s; ll mod = modular_exp(a, temp, p); while(temp != p - 1 && mod != 1 && mod != p - 1) { mod = mulmod(mod, mod, p); temp <<= 1; } if(mod != p - 1 && temp & 1) { return false; } } return true; } } } map mp = { {4,3}, {6,5}, {8,7}, {9,7}, {10,7}, {12,11}, {14,13}, {15,7}, {16,7}, {18,8}, {20,19}, {21,19}, {22,7}, {24,23}, {25,23}, }; int main() { string s; cin >> s; ll N = 0; rep(i, s.size()) { N = N * 10; N = N + (s[i] - '0'); } if(mp.find(N) != mp.end()) { cout << mp[N] << endl; exit(0); } if((N % 8 == 1) && math::prime::miller_rabin(N-8, 10000)) { cout << 14 << endl; } else { cout << 8 << endl; } return 0; }