import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

void main()
{
    auto nq = readln().split().map!(to!int);
    immutable n=nq[0], q=nq[1];
    int[][] r;
    for(int i=n; i>1; i=(i+1)/2)
        r~=new int[i];
    r~=new int[1];
    foreach(_;0..q)
    {
        auto av = readln().split().map!(to!int);
        auto a=av[0]-1, v=r[0][a]+av[1];
        foreach(t;r)
        {
            auto b = a^1;
            auto p = t[a];
            t[a]=v;
            if(b>=t.length)
            {
                a/=2;
            }
            else if(max(p,t[b])!=max(v,t[b]))
            {
                a/=2;
                v=max(v,t[b]);
            }
            else
            {
                break;
            }
        }
        a=0;
        foreach_reverse(t;r[0..$-1])
        {
            a*=2;
            if(a+1<t.length && t[a]<t[a+1])
                ++a;
        }
        writeln(a+1," ",r[0][a]);
    }
}