#include using namespace std; typedef long long ll; typedef vector vi; typedef vector vl; typedef complex P; typedef pair pii; #define REP(i,n) for(ll i=0;i=h||x>=w)return false; if(used[y][x])return false; used[y][x] = true; if(mp[y][x]==1e9)return false; if(mp[y][x]==n)return true; int t = mp[y][x]; bool flag = false; for(int k=2;k*k<=t;++k){ if(t%k==0){ flag = true; break; } } if(t==1)flag = true; if(!flag)return false; REP(i,4){ if( dfs(w,h,y+vy[i],x+vx[i]) ) return true; } return false; } int main(){ string s; cin >> s; if( !(s.size()<=2 && atoi(s.c_str())<30) ){ cout << 8 << endl; return 0; } n = atoi(s.c_str()); FOR(w,3,n){ int h = ceil((double)n/w); REP(i,h){ REP(j,w){ if(i*w+j>=n)mp[i][j] = 1e9; else mp[i][j]=i*w+j+1; used[i][j] = false; } } if( dfs(w,h,0,0) ){ cout << w << endl; return 0; } } return 0; }