perfectPowers :: Int -> [Int]
perfectPowers x = 1 : do
  b <- [2 .. 31]
  return $ last $ takeWhile (<= x) $ map (b^) [2..]

main :: IO ()
main = do
  x <- read <$> getLine
  print $ maximum $ perfectPowers x
