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
        no1, max1, no2, max2 = 0 ,0, 0, 0
        threads = []
        threads.push(Thread.new {no1, max1 = sums_even.max_by{|k, v| [v, -k]}})
        threads.push(Thread.new {no2, max2 = sums_odd.max_by{|k, v| [v, -k]}})
        threads.each {|t| t.join}
        case max1 <=> max2
          when 1; no , max = no1, max1
          when 0
            if no1 < no2
              no, max1 = no1, max1
            else
              no, max = no2, max2
            end
          when -1; no , max = no2, max2
        end
    end
    puts "#{no} #{max}"
  end
end