while gets do
  n, q = $_.split.map(&:to_i)
  sums, tops = {}, {}
  no, max, min = 0, 0, 0
  q.times do
    a, v = gets.split.map(&:to_i)
    sums[a] += v if sums[a] ||= 0
    tops[a] = sums[a] if sums[a] != nil || sums[a] > min
    case tops[a] <=> max
      when 1; no, max = a, tops[a]
      when 0; no, max = a, tops[a] if a < no
      when -1;(_no, min), (no, max) = tops.minmax_by{|k, v| [v, -k]}
    end
    puts "#{no} #{max}"
  end
end