findPrime' :: ([Int], [Int]) -> ([Int],[Int])
findPrime' ([], primes) = ([], primes)
findPrime' (prime:numbers, primes) =
    findPrime' (filter (\x -> x `mod` prime /= 0) numbers, prime:primes)

findPrime :: Int -> [Int]
findPrime x = reverse . snd $ findPrime' ([2..x], [])

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 (findPrime $ 2*x)
    putStrLn $ show ans
