object Main extends App {
    val x = io.StdIn.readInt

    if (x == 1) println(1)
    else {

        /*
        def exponentiation(base: Int): Int = {
            var tmp = base
            while (tmp < x) tmp *= base

            if (tmp == x) x
            else tmp/base
        }
        */

        def exponentiation(base: Int, acc: Int): Int =
            if (x < acc) acc/base
            else exponentiation(base, acc*base)

        // 1 <= 基数 <= √x
        val result = (2 to math.sqrt(x).toInt).map(exponentiation(_, 1)).max
        println(result)

    }

}