package abc097.b

import java.util.Scanner


object Main {
  def read() = {
    val sc = new Scanner(System.in)
    val x = sc.nextInt()
    x
  }


  /**
    * base^n (n>=2, base^n<=upperBound)のリストを返す
    */
  def parfectPowerList(base: Int, upperBound: Int): List[Int] = {
    if (base == 1) {
      return List(1)
    }

    // 初項a、公比baseの等比数列
    def recurrence(a: Int): Stream[Int] = a #:: recurrence(a * base)

    val stream = recurrence(base * base)

    stream.takeWhile(x => x <= upperBound).toList
  }

  def main(args: Array[String]): Unit = {
    val x: Int = read()
    val parfectPowersLessThanX = (1 to x).flatMap(i => parfectPowerList(i, x))
    val result = parfectPowersLessThanX.max
    println(result)
  }
}