import java.io.*;
import java.util.*;
public class solution2 {
	public static void main (String args []) throws Exception{
		BufferedReader r = new BufferedReader (new FileReader("DATA2.txt"));
		PrintWriter p = new PrintWriter ("OUT2.txt");
		int b [] = new int [25];
		b[0]=2;
		b[1]=3;
		int c = 2;
		for (int i = 5; i < 100; i++){
			boolean work = true;
			for (int l = i-1; l > 1; l--){
				if (Math.floor((double)i/(double)l)==((double)i/(double)l)){
					work = false;
				}
			}
			if (work){
				b[c]= i;
				c++;
			}
		}
		for (int h =  0 ; h < 5; h++){
			int num = Integer.parseInt (r.readLine());
			boolean sd = true;
			for (int i = 0; i <25; i++){
				if (b[i]==num){
					sd=false;
				}
				if (b[i]>num){
					c=i;
					
					break;
					
				}
			}
			if (sd){
			if (b[c+1]-num<num-b[c-2]){
				p.println (b[c+1]);
			}else if ((b[c+1]-num>num-b[c-2])){
				p.println (b[c-2]);
			}else{
				p.println (Math.max(b[c+1] , b[c-2]));
			}
			}else{
				if (b[c+1]-num<num-b[c-3]){
					p.println (b[c+1]);
				}else if(b[c+1]-num>num-b[c-3]){
					p.println (b[c-3]);
				}else{
					p.println (Math.max(b[c+1] , b[c-3]));
				}	
			}
			//p.println (Math.max(b[c+1] , num-b[c-2]));
			
		}
		p.close();
	}
}

