using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "Input3";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("101");
            //4
            //1,2,3はいずれも合成数ではありませんが、
            //4は1,4の他に2を約数として持つため合成数です。 
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("1000");
            //1000
            //N自身が合成数である場合、それを出力しても正答となります
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    //No.192 合成数
    static void Main()
    {
        List<string> InputList = GetInputList();
        int N = int.Parse(InputList[0]);

        for (int I = N - 100; I <= N + 100; I++) {
            if (IsPrime(I)) continue;
            Console.WriteLine(I);
            break;
        }
    }

    //素数かを判定
    static bool IsPrime(int pTarget)
    {
        for (int I = 2; I * I <= pTarget; I++) {
            if (pTarget % I == 0) return false;
        }
        return true;
    }
}