minus :: [Int] -> [Int] -> [Int]
minus (x : xs) (y : ys) = case (compare x y) of
  LT -> x : minus xs (y : ys)
  EQ -> minus xs ys
  GT -> minus (x : xs) ys
minus xs _ = xs

primesToQ :: Int -> [Int]
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 :: IO ()
main = do
  [x] <- map read . words <$> getLine
  let Just ans = lowerBoundValue x (primesToQ $ 2 * x)
  putStrLn $ show ans