/*
template   Dwite_IN_out_java.java
*/
import java.io.*;
import java.util.*;

class que2 {
	public static void main (String [] args) throws IOException {
	
    // Use BufferedReader rather than RandomAccessFile; it's much faster
    BufferedReader f = new BufferedReader(new FileReader("DATA2.txt"));
                                                  // input file name goes above
    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("OUT2.txt")));
    String s = f.readLine();                      // gets entire line
    int fr_num = Integer.parseInt(s); 
	int a = 0;
	int count = 0;
	int c= 0;
	do
	{
	if (aprime(fr_num - count) = false && aprime(fr_num + count) = false){
		count ++;
		}
	else {
		a++;
		}
	}
	while(a	< 2 || (fr_num - count) >= 1 || (fr_num +count) <3); 
	if (a>= 2){
		c = fr_num;
		}
	if (fr_num - count > = 2){
		c = fr_num
		}
	out.write(""+  c  + "\n" );  
    f.close();
    out.close();                                  // close the output file
    System.exit(0);                               // don't omit this!

  
   } // end main
	//	public static boolean aprime(int inp/*input*/){
			boolean prime = false;				// local boolean defined
			//int int_check = 1;
				for (int i = 2; i <= ((int)(Math.sqrt(inp)) + 1)/** the system checks up to squaroot of number*/; i += 1) { 
					if ( !(inp == 2) && (inp % i == 0)) {
						prime = false;
						break;				// the program doesn't check further number since it determines the boolean to be false
					}
					else{				//  prime
						prime = true;
					}
				}
				return(prime);			// returning local boolean
		}
		int b= 0;
		//do{
			
		
		//}
		//while(

}//end class
