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