#include <bits/stdc++.h> using namespace std; typedef __int128 Int; vector<bool> prime(100,true); void eratosthenes(){ for(int i=2;i<100;i++){ if(prime[i]){ for(int j=i*2;j<100;j+=i){ prime[j]=false; } } } } bool bfs(int w,int n){ vector<bool> used(1000,false); used[1]=true; used[0]=true; queue<int> que; que.push(1); while(que.empty()==false){ int v=que.front();que.pop(); if(v%w!=1&&used[v-1]==false&&prime[v-1]==false){ que.push(v-1); used[v-1]=true; } if(v%w!=0&&used[v+1]==false&&v+1<=n&&prime[v+1]==false){ que.push(v+1); used[v+1]=true; } if(v+w<=n&&used[v+w]==false&&prime[v+w]==false){ que.push(v+w); used[v+w]=true; } if(v-w>=1&&used[v-w]==false&&prime[v-w]==false){ que.push(v-w); used[v-w]=true; } } return used[n]; } 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<s;r++,_d<<=1){ b&=(powmod(a,_d,n)!=n-1); //print(powmod(a,_d,n)); if(powmod(a,_d,n)<0)cout<<"ERROR"<<endl; } if(b){return false;} } } return true; } int main(){ eratosthenes(); string S; cin>>S; if(S.size()<3){ int a=stoi(S); for(int w = 2; w < a; w++) if(bfs(w,a)){ cout<<w<<endl; return 0; } } else { Int a=0; for(auto& it : S){ a*=10; a+=(it-'0'); } a-=8; if((a%8==1)&&miller_rabin(a))cout<<14<<endl; else cout<<8<<endl; } return 0; }