#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main (){
	freopen ("data2.txt", "r", stdin);
	freopen ("out2.txt", "w", stdout);
	bool pr[201], f;
	double sq;
	int i, a, n, z, c=0, dist1, dist2, x, y;
	
	for (i=0; i<201; ++i){
		pr[i]=false;
	}
	pr[2]=true;
	pr[3]=true;
	pr[5]=true;
	for (i=7; i<201; i+=2){
		f=false;
		sq=sqrt(i);
		if (i%2!=0){
			for (a=3; a<=sq; ++a){
				if (i%a==0){
					f=true;
					break;
				}
			}
			if (f==false){
				pr[i]=true;
			}
		}
	}
	
	for (z=0; z<5; ++z){
		cin >> n;
		dist1=-1;
		x=-1;
		dist2=-1;
		y=-1;
		c=0;
		for (i=n+1; i<201 || !pr[i]; ++i){
			if (pr[i] && c==0){
				++c;
			}
			else if (pr[i] && c==1){
				dist1=i-n;
				x=i;
				break;
			}
		} 
		c=0;
		for (i=n-1; i>=0 || !pr[i]; --i){
			if (pr[i] && c==0){
				++c;
			}
			else if (pr[i] && c==1){
				y=i;
				dist2=n-i;
				break;
			}
		} 
		if (dist1==-1){
			cout << y << endl;
		}
		else if (dist2==-1){
			cout << x << endl;
		}
		else if (dist1<=dist2){
			cout << x << endl;
		}
		else if (dist2<dist1){
			cout << y << endl;
		}
	}
	
	return 0;
}

