#include <fstream>
using namespace std;
ifstream f1("bai2_14.inp");
ofstream f2("bai2_14.out");
bool kt2(long i)
{
    for (long j = 2; j*j <= i; j++)
    {
        if (i%j == 0) return 0;
    }
    return 1;
}
bool kt(long i)
{
    for (long j = 2; j*j <= i; j++)
    {
        if (i%j != 0) continue;
        if (kt2(i/j) == 1 && kt2(j) == 1) return 1;
    }
    return 0;
}
int main()
{
    long n;
    f1 >> n;
    for (long i = n; i >= 6; i--)
    {
        if(kt(i) == 1) {f2 << i;break;}
    }
    return 0;
}
