fun main(args: Array<String>) {

    val x = readInts()[0]
    
    println(getList().maxBy { it <= x })
}

fun getList() =
    (1 .. 31).flatMap {base ->
        (2 .. 9).map { Math.pow(base.toDouble(), it.toDouble()).toInt() }.filter { it <= 1000 }
    }.distinct().sortedDescending()

fun readInts(): List<Int> = readStrings().map { it.toInt() }
fun readStrings(): List<String> = readLine()!!.split(" ")