#include <iostream>
using namespace std;
int FindMaxZishu(int num)
{
for(int right = num;right>0;right--)
{
bool flag=true;
for(int i = 2;i<right-1;i++)
{
if(right%i == 0)
flag=false;
}
if(flag&&right!=1)
{
return right;
}
}
}
int main(int argc, char *argv[])
{
int num;
cin>>num;
cout<<FindMaxZishu(num)<<endl;
return 0;
}