#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
int INF=1e9;
int MOD=1000000007;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
double EPS = 1e-10;
bool is_prime(long long n){
    for(long long i=2;i*i<=n;i++){
        if(n%i==0)return false;
    }
    return true;
}
int main(){
	long long s;
	cin>>s;
	if(s==1){
		cout<<1<<endl;
		return 0;
	}
	if(s==4){
		cout<<3<<endl;
		return 0;
	}
	if(s==6){
		cout<<5<<endl;
		return 0;
	}
	if(s==8||s==9||s==10||s==15||s==16||s==22){
		cout<<7<<endl;
		return 0;
	}
	if(s==12){
		cout<<11<<endl;
		return 0;
	}
	if(s==14||s==15||s==16){
		cout<<13<<endl;
		return 0;
	}
	if(s==20||s==21||s==22){
		cout<<19<<endl;
		return 0;
	}
	if(s==24||s==25){
		cout<<23<<endl;
		return 0;
	}
	if(s%(long long)8!=1)cout<<8<<endl;
	else if(!is_prime(s-(long long)8))cout<<8<<endl;
	else cout<<14<<endl;
	return 0;
}