main = interact $ unlines . map (unwords . map show . prime2 . read) . lines

prime2 n = [last under, if o==n then (head over) else n]
 where (under,(o:over)) = break (>=n) primes

primes = 2:3:[x | i<-[1..], j<-[-1,1], let x = 6*i+j, isPrime x]
 where isPrime n = null [i | i<-takeWhile (\x -> x*x <= n) primes, rem n i == 0]