hash = Hash.new(0)
n,q = gets.split.map(&:to_i)
max_v,min_a = -Float::INFINITY,Float::INFINITY
q.times do
    a,v = gets.split.map(&:to_i)
    hash[a] += v
  if v > 0
      if hash[a] > max_v
        max_v = hash[a]
        min_a = a
      elsif hash[a] == max_v
      min_a = [a,min_a].min
      end
  else
      if a == min_a
        tmp = hash.sort do |(k1,v1),(k2,v2)|
          if v1 == v2
            k1 <=> k2
          else
            v2 <=> v1
          end
        end
  min_a,max_v = tmp.first[0],tmp.first[1]
      end
  end
  puts [min_a,max_v].join(" ")
end
