using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Numerics; using BI=System.Numerics.BigInteger; class TEST{ static void Main(){ Sol mySol =new Sol(); mySol.Solve(); } } class Sol{ public void Solve(){ int ans=0; int N2=0; if(N<100){ N2=(int)N; switch(N2){ case 4: ans=3;break; case 6: ans=5;break; case 8: ans=7;break; case 9: ans=7;break; case 10: ans=7;break; case 15: ans=7;break; case 16: ans=7;break; case 22: ans=7;break; case 33: ans=8;break; case 57: ans=8;break; case 65: ans=8;break; case 12: ans=11;break; case 14: ans=13;break; case 20: ans=19;break; case 21: ans=19;break; case 24: ans=23;break; case 25: ans=23;break; default: if(N%8==1){ ans=14; }else{ ans=8; }break; } Console.WriteLine(ans); return; } Console.WriteLine((N%8==1 && IsPrime(N-8))?14:8); } String S; BI N; public Sol(){ S=rs(); N=BI.Parse(S); } static bool IsPrime(BI x){ if(x==2)return true; if((x==1) || (x&1)==0)return false; if(x<(BI)1e12){ for(BI t=2;t*t<=x;t++){ if(x%t==0)return false; } return true; } return MillerRabinTest(x); } static bool MillerRabinTest(BI n){ int rep=20; BI d=n-1; // (n-1)=2^s*d while((d&1)==0)d>>=1; var rnd=new Xor128(); BI a=1+((BI)rnd.Next())%(n-2); while(rep>0){ rep--; a=1+((BI)rnd.Next()*a)%(n-2); BI t=d; BI y=ModPowBI(a,t,n); while(t!=(n-1) && y!=1 && y!=n-1){ y=y*y%n; t<<=1; } if(y!=(n-1) && (t&1)==0)return false; } return true; } static BI ModPowBI(BI a,BI t,BI mod){ BI ret=1; while(t>0){ if((t&1)==1){ret*=a;ret%=mod;}; a=a*a;a%=mod; t>>=1; } return ret; } static String rs(){return Console.ReadLine();} static int ri(){return int.Parse(Console.ReadLine());} static long rl(){return long.Parse(Console.ReadLine());} static double rd(){return double.Parse(Console.ReadLine());} static String[] rsa(){return Console.ReadLine().Split(' ');} static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));} static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));} static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));} } class Xor128{ static uint x = 123456789; static uint y = 362436069; static uint z = 521288629; static uint w = 88675123; uint t; public Xor128(){ } public Xor128(uint seed){ z ^= seed; z ^= z >> 21; z ^= z << 35; z ^= z >> 4; } public uint Next(){ t = x ^ (x << 11); x = y; y = z; z = w; return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); } public int Next(int ul){ return NextI(0,ul-1); } public int NextI(int from,int to){ int mod=to-from+1; int ret=(int)(Next()%mod); return ret+from; } }