import Control.Monad
import Text.Printf
import Control.Applicative
import Data.List as L

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO()
main = do
  [x] <- getInts
  let a = [2^y | y <- [2..9]]
      b = [y^2 | y <- [1..31]]
      c = [y^3 | y <- [1..10]]
      d = [y^4 | y <- [1..5]]
      e = [y^5 | y <- [1..3]]
      f = [y^6 | y <- [1..3]]
  printf "%d" $ head $dropWhile (> x) $ sortBy (flip compare) (concat [a, b, c, d, e, f])