class IdFish
  def initialize(i,f)
    @id,@fish = i,f
  end
  attr_accessor :id,:fish
end

q = gets.split.last.to_i
a = Array.new
q.times do
  id,fish = gets.split.map(&:to_i)
  if i = a.index{|x| x.id == id}
    a[i].fish += fish
  else
    a << IdFish.new(id,fish)
  end
  a.sort!{|x,y| x.fish<=>y.fish}
  puts "#{a[-1].id} #{a[-1].fish}"
end