function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}
function Main(input) {
  input = myconv(input,1);
  for(var i = input; i > 0; i--){
        var list = getDivisorList(i);
    	if(list.length == 1 || list.length == 2){
           continue;
           }
    	var tmp = myconv(i.toString(),1);
    while(tmp != 1){
          if(tmp % list[1] == 0){
             tmp /= list[1];
            if(tmp == 1){
               myout(i);
              return;
            }
          }else{
            break;
          }
    }
  }
  myout(1);
}
function getDivisorList(val){
        var list = [];
        for(var i = 1; i * i <= val; i++){
                if(val % i == 0){
                        list.push(i);
                        if(i * i != val){
                                list.push(val / i);
                        }
                }
        }
        list.sort(function(a,b){
                return a - b;
        });
        return list;
}
Main(myin());