#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)


int main(){
    int n, m;
    cin >> n >> m;
    map<int, int> mp;
    priority_queue<pii> q;
    rep(i, m){
        int a, b;
        cin >> a >> b;
        mp[a] += b;
        q.push(make_pair(mp[a], -a));
        while(true){
            pii p = q.top();
            if(mp[-p.second] == p.first){
                cout << -p.second << " " << p.first << endl;
                break;
            }
            q.pop();
        }
    }
}