#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; typedef long double ld; const ll INF = 1e+14; typedef pair P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i=0;i--) #define Rep(i,sta,n) for(int i=sta;i=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef complex Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair LDP; typedef pair LP; #define fr first #define sc second const int mn = 2001; bool isp[mn + 1]; void init() { fill(isp + 2, isp + mn + 1, true); Rep1(i, 2, mn) { if (!isp[i])continue; for (int j = 2 * i; j <= mn; j += i) { isp[j] = false; } } } bool testmincase(int n, int m) { if (isp[n])return false; vector used(n, false); queue q; q.push(0); used[0] = true; rep(i, n) { if (isp[i + 1])used[i] = true; } while (!q.empty()) { int id = q.front(); q.pop(); if (id%m) { if (!used[id - 1]) { used[id - 1] = true; q.push(id - 1); } } if ((id%m) < m - 1 && id < n - 1) { if (!used[id + 1]) { used[id + 1] = true; q.push(id + 1); } } if (id - m >= 0) { if (!used[id - m]) { used[id - m] = true; q.push(id - m); } } if (id + m < n) { if (!used[id + m]) { used[id + m] = true; q.push(id + m); } } } return used[n - 1]; } void solve() { init(); string s; cin >> s; if (s.length() > 15) { cout << 8 << endl; return; } else if(s.length()<=2){ int n = stoi(s); rep1(i, n) { if (testmincase(n, i)) { cout << i << endl; return; } } } else { ll c = stoll(s); c -= 8; ll k = sqrt(c); if (c % 8 != 1) { cout << 8 << endl; return; } Rep1(i,2, k) { if (i == c)continue; if (c%i == 0) { cout << 8 << endl; return; } } cout << 14 << endl; return; } } int main() { solve(); //stop return 0; }