import           Data.List
import           Control.Applicative
import           Control.Monad

sosus :: [Int]
sosus = sosu [2 ..]
sosu :: [Int] -> [Int]
sosu (x : xs) = x : sosu (filter (\n -> mod n x /= 0) xs)

yakus :: Int -> [Int]
yakus 1 = []
yakus n = case filter (\l -> mod n l == 0) (takeWhile (<= n) sosus) of
  []      -> [n]
  (x : _) -> x : yakus (div n x)

distinct :: [Int] -> [Int]
distinct []  = []
distinct [x] = [x]
distinct (x1 : x2 : xs) | x1 == x2  = distinct $ x2 : xs
                        | otherwise = x1 : distinct (x2 : xs)

judge :: Int -> Bool
judge 1 = True
judge n = sz == 1 && head xs /= n
 where
  xs = (distinct . yakus) n
  sz = length xs

main = do
  n <- readLn
  print $ maximum $ filter judge [1 .. n]
