#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; } } template value_type mod_pow(value_type x, value_type n, value_type mo) { value_type ret = 1; while(n > 0) { if(n & 1) { ret = ret * x % mo; } x = x * x % mo; n >>= 1; } return ret; } namespace math { namespace prime { bool miller_rabin(ll p,int iteration) { if(p < 2) { return false; } if (p != 2 && p % 2==0) { return false; } ll s = p - 1; while(s % 2 == 0) { s /= 2; } rep(_, iteration) { ll a = std::random_device()() % (p - 1) + 1, temp = s; // これもうわかんねぇな ll mod = mod_pow(a, temp, p); while (temp != p - 1 && mod != 1 && mod != p - 1) { mod = mulmod(mod, mod, p); temp *= 2; } if (mod != p - 1 && temp % 2 == 0) { return false; } } return true; } } } typedef ll Int; Int mulmod(Int a,Int n,Int Mod){ Int res=0; while(n){ if(n&1)res=(res+a)%Mod; a=(a+a)%Mod; n>>=1; } return res; } Int powmod(Int a,Int n,Int Mod){ Int res=1; while(n){ if(n&1)res=mulmod(res,a,Mod); a=mulmod(a,a,Mod); n>>=1; } return res; } bool miller_rabin(Int n){ Int d=n-1,s=0; while(d%2==0){ d/=2; s+=1; } for(int k=2;k<100;k++){ // if(!prime[k])continue; Int a=k; if(powmod(a,d,n)!=1){ bool b=true; for(Int r=0,_d=d;r 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; }