{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}

main :: IO ()
main = do
  x <- readLn
  print $ solve x

solve :: Int -> Int
solve x = head $ filter isExpNumber [x, x-1 ..]

isExpNumber :: Int -> Bool
isExpNumber 1 = True
isExpNumber x = any g [b | b <- [2 .. x], x `mod` b == 0] where
  g b = any (x ==) $ takeWhile (x >=) [b ^ p | p <- [2 ..]]
