import qualified Data.Set as S eratosthenes n = f [] [2..n] where f pn ys | pn /= [] && (head pn)^2 > n = (reverse pn) ++ ys | otherwise = f ((head ys):pn) (filter (p (head ys)) ys) p m z = z `mod` m /= 0 solve' n = head (S.toList (S.difference (S.fromList [m..n]) (S.fromList pn))) where m | n - 100 < 2 = 2 | otherwise = n - 100 pn = filter p (eratosthenes n) p x = x >= n - 100 && x <= n + 100 main = readLn >>= print . solve'