mymappend :: (a->[a])->[a]->[a]
mymappend _ [] = []
mymappend f (e:es) = mappend (f e) (mymappend f es)

manipu :: Int->Int->[Int]
manipu x b = manipu' (b*b)
  where
    manipu' :: Int -> [Int]
    manipu' c = if c<=x
                then c:(manipu' (c*b))
                else []

main = do
  x <- readLn :: IO Int
  putStrLn $ show $ maximum $ 1:(mymappend (manipu x) [2..1000])
