#include <fstream>
using namespace std;
int main()
{
    ifstream f1("ntmax.inp");
    ofstream f2("ntmax.out");
    long x;
    f1 >> x;
    f1.close();
    long n = 1;
    while (n > 0)
    {
        n = 0;
        for (long m = 2; m*m <= x; m++)
        {
            if (x%m == 0) n = 1;
        }
        x--;
    }
    f2 << x+1;
    f2.close();
    return 0;
}
