import sys
data=sys.stdin.readlines() # 把輸入的值一起放入
n,m=map(int, data[0].split()) # n,m 是第一行的兩個數字 (幾個觀眾n , 禮物次數m)
box={i:0 for i in range(n)} # for i in range(n) # 把編號先處理出來 n-1個 因為包括0)
for i in range(1,m+1):
a,b=map(int, data[i].split()) # 把禮物跟編號逐一放入
box[a]+=b
ans=sorted(box.items(), key=lambda x:(-x[1], x[0])) # 排序 items 把字典轉列表
x:(-x[1], x[0]) -x[1] 是禮物的價格(優先排 由大到小) x[0]再來就是編號由小到大
sys.stdout.write("".join(f"{a} {b}\n" for a, b in ans))