main = do
  s <- getContents
  mapM_ (\n -> putStrLn . unwords $ map show $ [last $ takeWhile (< n) $ primes [2..], head $ dropWhile (<= n) $ primes [2..]]) . map read $ lines s
primes :: [Int] -> [Int]
primes = primes' where primes' [] = []; primes' (p:xs) = p : primes' [x | x <- xs, mod x p /= 0]