inputs = lambda: list(map(int, input().split()))

n_, q = inputs()

n = 1

while n<=n_: n *= 2

data = [(0, -n)] * (2*n+1)

for t in range(q):

    a, v = inputs()

    i = a + (n-1)

    data[i] = (data[i][0]+v, -a)

    while i:

        i = (i - 1) / 2

        data[i] = max(data[2*i+1], data[2*i+2])

    p, q = data[0]

    print(-q, p)
from heapq import heappush, heappop

inputs = lambda: list(map(int, input().split()))

n, q = inputs()

n += 1

que = [(0, 1, -1)]

data = [0] * n

T = [-1] * n

for t in range(q):

    a, v = inputs()

    data[a] += v

    T[a] = t



    heappush(que, (-data[a], a, t))

    while 1:

        v, k, p = heappop(que)

        if T[k] == p:

            print(k, -v)

            heappush(que, (v, k, p))

            break
inputs = lambda: list(map(int, input().split()))
n_, q = inputs()
n = 1
while n <= n_:
    n *= 2
data = [(0, -n)] * (2 * n + 1)
for t in range(q):
    a, v = inputs()
    i = a + (n - 1)
    data[i] = (data[i][0] + v, -a)
    while i:
        i = (i - 1) / 2
        data[i] = max(data[2 * i + 1], data[2 * i + 2])
    p, q = data[0]
    print(-q, p)

from heapq import heappush, heappop

inputs = lambda: list(map(int, input().split()))
n, q = inputs()
n += 1
que = [(0, 1, -1)]
data = [0] * n
T = [-1] * n
for t in range(q):
    a, v = inputs()
    data[a] += v
    T[a] = t
    heappush(que, (-data[a], a, t))
    while 1:
        v, k, p = heappop(que)
        if T[k] == p:
            print(k, -v)
            heappush(que, (v, k, p))
            break

+from heapq import heappush, heappop + -n_, q = inputs() -n = 1 -while n <= n_: -    n *= 2 -data = [(0, -n)] * (2 * n + 1) +n, q = inputs() +n += 1 +que = [(0, 1, -1)] +data = [0] * n +T = [-1] * n -    i = a + (n - 1) -    data[i] = (data[i][0] + v, -a) -    while i: -        i = (i - 1) / 2 -        data[i] = max(data[2 * i + 1], data[2 * i + 2]) -    p, q = data[0] -    print(-q, p) +    data[a] += v +    T[a] = t +    heappush(que, (-data[a], a, t)) +    while 1: +        v, k, p = heappop(que) +        if T[k] == p: +            print(k, -v) +            heappush(que, (v, k, p)) +            break