import Control.Applicative ((<$>)) import Data.List (find) main :: IO () main = solve <$> read <$> getLine >>= print solve :: Int -> Int solve n = maybe (f n) id . find ((== 0) . (mod n)) . takeWhile ((<= n) . (^ 2)) $ [3 ..] where f x | even x = let y = x `div` 2 in if y > 2 then y else x | otherwise = x