import           Data.Array.Unboxed

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

primesToG :: Int -> [Int]
primesToG m = 2 : sieve [3, 5 .. m]
 where
  sieve (p : xs) | p * p > m = p : xs
                 | otherwise = p : sieve (xs `minus` [p * p, p * p + 2 * p ..])
  sieve _ = []

primesToA :: Int -> [Int]
primesToA m = sieve
  3
  (array (3, m) [ (i, odd i) | i <- [3 .. m] ] :: UArray Int Bool)
 where
  sieve :: Int -> UArray Int Bool -> [Int]
  sieve p a
    | p * p > m = 2 : [ i | (i, True) <- assocs a ]
    | a ! p =  sieve (p + 2)
    $  a
    // [ (i, False) | i <- [p * p, p * p + 2 * p .. m] ]
    | otherwise = sieve (p + 2) a

lowerBound'' :: (Ord a) => a -> Int -> Int -> [a] -> Int
lowerBound'' num left right arr
  | right == left + 1 = right
  | midValue < num    = lowerBound'' num mid right arr
  | otherwise         = lowerBound'' num left mid arr
 where
  mid      = (left + right) `div` 2
  midValue = arr !! mid

lowerBound :: (Ord a) => a -> [a] -> Int
lowerBound num arr | num <= head arr = 0
                   | last arr < num  = length arr
                   | otherwise       = lowerBound'' num 0 (length arr - 1) arr

lowerBoundValue :: (Ord a) => a -> [a] -> Maybe a
lowerBoundValue num arr | i == length arr = Nothing
                        | otherwise       = Just (arr !! i)
  where i = lowerBound num arr

main :: IO ()
main = do
  [x] <- map read . words <$> getLine
  let Just ans = lowerBoundValue x (primesToG $ 2 * x)
  putStrLn $ show ans