import Control.Applicative ((<$>))
import Data.List (sortBy)

main :: IO ()
main = solve <$> readLn >>= print
  
solve :: Int -> Int
solve n = head $ dropWhile (>n) lst
  where lst = sortBy (flip compare) . concat $ [1] : [ takeWhile (<= 1000) $ map (b^) [2..]| b <- [2 .. 31]]
