/**
 * @(#)iProfits.java
 *
 *
 * @author 
 * @version 1.00 2009/10/21
 */

import java.io.*;
import java.lang.*;

public class S2 {

	public static void main(String args[]) throws Exception {
		BufferedReader in = new BufferedReader(new FileReader("DATA2.txt"));
		PrintWriter outputStream = new PrintWriter(new BufferedWriter(new FileWriter("OUT2.txt")));
		int[] line = {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} ;

		for (int i=0; i<5; i++) {
			String a = in.readLine();
			int c = Integer.parseInt(a);
		
			for (int d = 0; d < 25; d++) {

				if (c == line[d]){
					if (c - line[d-2] > line[d+2] - c ) {
						outputStream.println(line[d+2]);
						break;
					}
					else {
						outputStream.println(line[d-2]);
						break;
					}
				}
				
				else if (c > line[d]) {
					if ( c < line[d+1]) {
						if ( (line[d+2] - c) > (c - line[d - 1])) {	
							outputStream.println(line[d - 1]);
							break;
						} else {
							outputStream.println(line[d+2]);
							break;
						}
					} else 
						continue;
				} else 
					continue;

			}

		}
		outputStream.close();
		System.exit(0);
	}
}
		
