n = 50021
a = Array.new(n){|i| i+1}
a[0] = 0
(2..n**(0.50)).each do |i|
  (2..(n/i)).each{|j| a[i*j-1] = 0} if a[i-1]>0
end
a.delete(0)

while gets
  q = $_.to_i
  i = 1
  while a[i] < q do i+=1 end
  puts "#{a[i-1]}, #{a[i]==q ? a[i+1]:a[i]}"
end