import Data.List
import Data.List.Ordered (minus, union, unionAll)
 
primesToQ m = eratos [2..m] 
    where
    eratos []     = []
    eratos (p:xs) = p : eratos (xs `minus` [p*p, p*p+p..m])
 
lowerBound'' :: (Ord a) => a -> Int -> Int -> [a] -> Int
lowerBound'' num left right array
    | right == left + 1 = right
    | midValue < num = lowerBound'' num mid right array
    | otherwise = lowerBound'' num left mid array
    where mid = (left + right) `div` 2
          midValue = array !! mid
 
lowerBound :: (Ord a) => a -> [a] -> Int
lowerBound num array
    | num <= head array = 0
    | last array < num = length array
    | otherwise = lowerBound'' num 0 (length array - 1) array
 
lowerBoundValue :: (Ord a) => a -> [a] -> Maybe a
lowerBoundValue num array
    | i == length array = Nothing
    | otherwise = Just (array !! i)
    where i = lowerBound num array
 
main = do
    [x] <- map read . words <$> getLine
    let Just ans = lowerBoundValue x (primesToQ $ 2*x)
    putStrLn $ show ans