while gets do
  n, q = $_.split.map(&:to_i)
  sums_even = {}
  sums_odd = {}
  no, max = 0, 0
  q.times do
    a, v = gets.split.map(&:to_i)
    sums = a.even? ? sums_even : sums_odd
    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
        max_even, max_odd = nil, nil
        threads = []
        threads.push(Thread.new {max_even = sums_even.size == 0 ? [nil, nil] : sums_even.max_by{|k, v| [v, -k]}})
        threads.push(Thread.new {max_odd = sums_odd.size == 0 ? [nil, nil] : sums_odd.max_by{|k, v| [v, -k]}})
        threads.each {|t| t.join}
        case max_even[1] <=> max_odd[1]
          when 1; no, max = max_even
          when 0; no, max = max_even[0] < max_odd[0] ? max_even : max_odd
          when -1; no, max = max_odd
        end
    end
    puts "#{no} #{max}"
  end
end