import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class Q2 {
	public static void main(String arg[]) throws IOException{
		
		BufferedWriter w = new BufferedWriter(new FileWriter(new File("OUT2.txt")));
		Scanner s = new Scanner (new File("DATA2.txt"));
		int[] x = new int[5];
		int[][] y = new int[5][2];
		for (int i =0;i<5;i++){
			x[i] = s.nextInt();
			boolean test1 = true;
			boolean test2 = true;
			int temp1 = x[i];
			int temp2 = x[i];
			while (test1){
				temp1--;
				if (ifPrime(temp1)) {
					
					while (test1){
						temp1--;
					if (ifPrime(temp1)){
						y[i][0] = temp1;
						test1 = false;
					}
					}
			}
			}
			while (test2){
				temp2++;
				if (ifPrime(temp2)) {
					while (test2){
						temp2++;
					if (ifPrime(temp2)){
						y[i][1] = temp2;
						test2 = false;
					}
					}
			}
		}
		}
		
		for (int i =0; i <5;i++){
			if ( (x[i] - y[i][0]) > (y[i][1] - x[i]) ){
				w.write(y[i][1] + "\n");
			} else if( (x[i] - y[i][0]) < (y[i][1] - x[i])){
				w.write(y[i][0] + "\n");
			} else {
				w.write(Math.max(y[i][0],y[i][1]) + "\n");
			}
			
			
		}
		w.close();
		s.close();
		
	}
	static boolean ifPrime(int x){
		int[] list = { 2, 3 ,5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113 ,127, 131, 137 ,139 ,149};
		for (int i = 0 ; i < list.length ; i++ ){
			if (x == list[i]) return true;
		}
		return false;
	
	}
}

