#pragma GCC target("avx")
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DB double
#define LD long double
#define ST string
#define BS bitset
#define PA pair<LL,LL>
#define VE vector
#define VL vector<LL>
#define VP vector<pair<LL,LL>>
#define VVL vector<vector<LL>>
#define PQ priority_queue
#define PQS priority_queue<LL,vector<LL>,greater<LL>>
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define EB emplace_back
#define MP make_pair
#define TS to_string
#define TU to_ullong
#define BPL __builtin_popcountll
#define FOR(i,a,n) for(i=a;i<n;++i)
#define FORR(i,a,n) for(i=n-1;i>=a;--i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) FORR(i,0,n)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define UB(a,n) *upper_bound(ALL(a),n)
#define LB(a,n) *lower_bound(ALL(a),n)
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000001
#define NUM 200010
#define FAST cin.tie(0);ios::sync_with_stdio(false)

void Yn(LL a){if(a)printf("Yes\n");else printf("No\n");}
void YN(LL a){if(a)printf("YES\n");else printf("NO\n");}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL dig(LL n){LL ret=0;while(n)n/=10,ret++;return ret;}
LL LBn(VL &v,LL a){LL mx=v.size(),mn=-1,md;while(mx-mn>1){md=(mx+mn)/2;if(v[md]<a)mn=md;else mx=md;}return mx;}
LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL cmod(LL a,LL m){if(a%m<0)return a%m+abs(m);else return a%m;}
LL DIV(LL a,LL d,LL m){LL l=m,x=1,y=0,k;while(l){k=d/l;d-=k*l;swap(l,d);x-=k*y;swap(x,y);}return cmod(a*cmod(x,m),m);}
LL POW(LL a,LL n,LL m){LL ans=1;while(n>0){if(n&1)ans=ans*a%m;a=a*a%m;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
bool cmps(pair<LL,LL> a,pair<LL,LL> b){if(a.second!=b.second)return a.second<b.second;return a.first<b.first;}
template<typename T>bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

struct ifprf{
private:VVL pri;
	bool ifpr(LL p){if(p<=1)return 0;if(p==2||p==3||p==5)return 1;if(p%2==0||p%3==0||p%5==0)return 0;LL i,j,n[8]={7,11,13,17,19,23,29,31},r=(LL)sqrt(p)+1;FOR(i,0,8)for(j=n[i];j<=r;j+=30)if(p%j==0)return 0;return 1;}
	LL pr_mod(LL a,LL b,LL m){a%=m,b%=m;if(a<=INT_MAX&&b<=INT_MAX)return a*b%m;LL ret=0,i;VL v;while(b)v.PB(b%10),b/=10;repr(i,(LL)v.size())ret*=10,ret%=m,ret+=v[i]*a%m,ret%=m;return ret;}
	LL pr_pow(LL a,LL n,LL m){LL ret=1;while(n){if(n&1)ret=pr_mod(ret,a,m);a=pr_mod(a,a,m);n>>=1;}return ret;}
	void pr_div(LL p,LL &s,LL &d){LL S=0;while(p%2==0)++S,p/=2;s=S,d=p;}
	bool calc(LL p,LL a){LL i,s,d,m;pr_div(p-1,s,d);m=pr_pow(a,d,p);if(m==1||m==p-1)return 1;rep(i,s-1){m=pr_pow(m,2,p);if(m==p-1)return 1;}return 0;}
public:ifprf(){pri.PB({31,73});pri.PB({2,7,61});pri.PB({2,379215,457083754});pri.PB({2,1215,34862,574237825});pri.PB({2,3,5,7,11,13,17,19,23,29});}
	bool p(LL n){if(n<10000)return ifpr(n);else if(n<9080191)for(LL i:pri[0]){if(!calc(n,i))return 0;}else if(n<4759123141)for(LL i:pri[1]){if(!calc(n,i))return 0;}else if(n<75792980677)for(LL i:pri[2]){if(!calc(n,i))return 0;}else if(n<21652684502221)for(LL i:pri[3]){if(!calc(n,i))return 0;}else for(LL i:pri[4]){if(!calc(n,i))return 0;}return 1;}
};

int main(){
  FAST;
	LL X;
	cin>>X;
	ifprf f;
	while(1){
		if(f.p(X)){
			cout<<X<<endl;
			return 0;
		}
		++X;
	}
}


Measured memory_bytes: 384