import Control.Applicative
import Control.Monad
import Data.List
import Data.Array
import Data.Char

main = do
  x <- (read::String -> Int) <$> getLine
  print . head . filter (\n -> judge n 2) $ reverse [1..x]

judge::Int -> Int -> Bool
judge n m
  | n == 1 = True
  | m * m > n = False
  | otherwise = if isPower n m then True else judge n (m + 1)

isPower::Int -> Int -> Bool
isPower n m
  | n == 1 = True
  | otherwise = if n `mod` m /= 0 then False else isPower (n `div` m) m

