class Fisherman
  attr_accessor :id, :num;
  def initialize(id, num)
    @id = id
    @num = num
  end
  def >(other)
    if self.num == other.num && self.id > other.id
        return true
    elsif self.num > other.num
      return true
    end
    return false
  end
  def <(other)
    if self.num == other.num && self.id < other.id
        return true
    elsif self.num < other.num
      return true
    end
    return false
  end
end

q = gets.split.map(&:to_i)[1]

h = [] # heap
id = {} #

q.times{|i|
  a, v = gets.split.map(&:to_i)
  if id[a]
    queue = [0]
    pp = 0
    while queue.size > 0
      pp = queue.shift
      if h[pp].id == a
        break
      end
      l = 2*pp+1
      queue << l if h[l] && h[l].num >= id[a]
      r = 2*pp+2
      queue << r if h[r] && h[r].num >= id[a]
    end
    id[a] += v
    h[pp].num += v
    if v > 0
      cc = pp
      pp = (cc+1)/2-1
      while cc > 0 && h[pp] < h[cc]
        h[pp], h[cc] = h[cc], h[pp]
        cc = pp
        pp = (cc+1)/2-1
      end
    else
      loop do
        maxid = pp
        l = 2*pp+1
        maxid = l if h[l] && h[l] > h[maxid]
        r = 2*pp+2
        maxid = r if h[r] && h[r] > h[maxid]
        break if maxid == pp
        h[maxid], h[pp] = h[pp], h[maxid]
        pp = maxid
      end
    end
  else
    h << Fisherman.new(a, v)
    cc = h.size - 1
    pp = (cc+1)/2-1
    while cc > 0 && h[pp] < h[cc]
      h[pp], h[cc] = h[cc], h[pp]
      cc = pp
      pp = (cc+1)/2-1
    end
    id[a] = v
  end
  mval = h[0].num
  mid = h[0].id

  queue = [0]
  pp = 0
  while queue.size > 0
    pp = queue.shift
    mid = h[pp].id if mid > h[pp].id
    l = 2*pp+1
    queue << l if h[l] && h[l].num >= mval
    r = 2*pp+2
    queue << r if h[r] && h[r].num >= mval
  end
  puts [mid, mval].join(" ")
}