require 'prime'
def prm(n)
  a = Array.new(n){|i| i+1}
  a[0] = 0
  (2..n**(0.50)).each do |i|
    if a[i-1]>0 then
      (2..(n/i)).each do |j|
        a[i*j-1] = 0
      end
    end
  end
  b = a.max
  a[a.index(b)] = 0
  loop{break if (b+=1).prime?}
  puts "#{a.max} #{b}"
end

while gets
  prm($_.to_i)
end