import Control.Applicative
import Data.List

a = [2..31]
f x = takeWhile (<=1000) $ map (x^) [2..]
c = sort $ nub (1:(concat (map f a)))
main = do
    x <- readLn
    print $ head (reverse (takeWhile (<=x) c))
