#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

template <typename monoid>
struct segment_tree {
    using M = monoid;
    using T = typename M::value_type;

    std::size_t sz;
    std::vector<T> x;

    segment_tree(std::size_t n = 0) {
        sz = 1;
        while (sz < n) sz *= 2;
        x.assign(sz * 2, M::id());
        initialize();
    }

    template <typename iterator>
    segment_tree(iterator first, iterator last) {
        sz = 1;
        std::size_t n = std::distance(first, last);
        while (sz < n) sz *= 2;
        x.assign(sz * 2, M::id());
        std::copy(first, last, x.begin() + sz);
        initialize();
    }

    void fill(const T &val) {
        std::fill(x.begin() + sz, x.end(), val);
        initialize();
    }

    void initialize() {
        for (int i = (int)sz - 1; i >= 1; --i) {
            x[i] = M::op(x[i * 2 + 0], x[i * 2 + 1]);
        }
    }

    T accumulate(std::size_t l, std::size_t r) const {
        T al = M::id(), ar = M::id();
        for (l += sz, r += sz; l < r; l /= 2, r /= 2) {
            if (l & 1) al = M::op(al, x[l++]);
            if (r & 1) ar = M::op(x[--r], ar);
        }
        return M::op(al, ar);
    }

    void update(std::size_t i, const T &val) {
        x[i += sz] = val;
        while (i > 1) {
            x[i / 2] = M::op(x[i], x[i ^ 1]);
            i /= 2;
        }
    }

    T operator[](std::size_t i) const { return x[sz + i]; }
};

struct max_monoid {
    using value_type = pair<int, int>;
    static constexpr value_type id() { return {std::numeric_limits<int>::max(), 0}; }
    static value_type op(const value_type &a, const value_type &b) { 
        if(a.second>b.second || (a.second==b.second && a.first < b.first)) return a;
        else return b;
    }
};



int main() {
    int n, q;
    cin >> n >> q;
    segment_tree<max_monoid> segtree(n+1);
    for(int i=1; i<=n; i++) segtree.update(i, {i, 0});
    while(q--) {
        int a, v;
        cin >> a >> v;
        const auto& now = segtree[a];
        segtree.update(a, {a, now.second+v});
        auto&& top = segtree.accumulate(1, n+1);
        cout << top.first << " " << top.second << endl;
    }
    
    return 0;
}

