primes :: Integral a => [a]
primes = map fromIntegral $ [2, 3] ++ primes'
  where
    -- primes' :: Integral a => [a]
    primes' = [5] ++ f 1 7 primes'
    -- f :: Integral a => a -> a -> [a] -> [a]
    f m s (p:ps) = [n | n <- ns , gcd m n == 1] ++ f (m * p) (p * p) ps
      where
        ns = [x + y | x <- [s, s + 6 .. p * p - 2], y <- [0, 4]]


main :: IO ()
main = do
  n <- readLn :: IO Int
  print $ head $ dropWhile (n <=) primes