import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (x : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  print .  head . dropWhile (< x) $ primes

primes :: [Int]
primes = 2 : 3 : f 2 candidates
  where
    f :: Int -> [Int] -> [Int]
    f l cs = c' : f (succ l) cs'
      where
        (c' : cs') = dropWhile (\c -> any ((== 0) . mod c) (take l primes)) cs
    candidates :: [Int]
    candidates = [1..] >>= \i -> (6 * i +) <$> [(-1), 1]

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n
