#include <bits/stdc++.h>
#define maxv 10000
#define INF maxv
#define iOS ios::sync_with_stdio(false);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define e1 get<0>
#define e2 get<1>
#define e3 get<2>
#define ins insert
#define ms memset
#define so sizeof
#define itr ::iterator
#define in_an for(i=0;i<n;i++) cin>>a[i]
#define in_bn for(i=0;i<n;i++) cin>>b[i]
#define fin for(i=0;i<n;i++)
#define fim for(i=0;i<m;i++)
#define fjn for(j=0;j<n;j++)
#define fjm for(j=0;j<m;j++)
#define bi back_inserter
#define v1 a,b,c,d;
#define v2 i,j,k,l;
#define v3 p,q,r,s;
#define pll pair<long,long>

using namespace std;

//MiCr0-!cE

bool mycomp(tuple<long,bool,long> a,tuple<long,bool,long> b)
{
    if(e1(a)<e1(b)) return true;
    else if(e1(a)>e1(b)) return false;
    else
    {
        if(e2(a)) return true;
        else return false;
    }
}

int main()
{
    iOS
    long n,m; cin>>n>>m;
    tuple<long,bool,long> a[m];
    for(long i=0;i<m;i++)
    {
        cin>>e1(a[i])>>e2(a[i]); e3(a[i])=i;
    }
    sort(a,a+m,mycomp);
    pair<long,long> ans[m];
    long t1,t2,t3;
    bool xx=true;t1=2;t2=2;t3=3;
    for(long i=0;i<m;i++)
    {
        if(e2(a[i]))
        {
            ans[e3(a[i])]=mp(1,t1++);
        }
        else
        {
            if(t1<=t3) xx=false;
            ans[e3(a[i])]=mp(t2,t3++);
            if(t3>=t1)
            {
                t2++;
                t3=t2+1;
            }
        }
    }
    if(t1!=n+1) xx=false;
    if(!xx) cout<<"-1";
    else
    {
        for(long i=0;i<m;i++)
            cout<<ans[i].ff<<" "<<ans[i].ss<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
#define maxv 10000
#define INF maxv
#define iOS ios::sync_with_stdio(false);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define e1 get<0>
#define e2 get<1>
#define e3 get<2>
#define ins insert
#define ms memset
#define so sizeof
#define itr ::iterator
#define in_an for(i=0;i<n;i++) cin>>a[i]
#define in_bn for(i=0;i<n;i++) cin>>b[i]
#define fin for(i=0;i<n;i++)
#define fim for(i=0;i<m;i++)
#define fjn for(j=0;j<n;j++)
#define fjm for(j=0;j<m;j++)
#define bi back_inserter
#define v1 a,b,c,d;
#define v2 i,j,k,l;
#define v3 p,q,r,s;
#define pll pair<long,long>

using namespace std;

//MiCr0-!cE

bool mycomp(tuple<long,bool,long> a,tuple<long,bool,long> b)
{
    if(e1(a)<e1(b)) return true;
    else if(e1(a)==e1(b)&&e2(a)) return true;
        return false;
}

int main()
{
    iOS
    long n,m; cin>>n>>m;
    tuple<long,bool,long> a[m];
    for(long i=0;i<m;i++)
    {
        cin>>e1(a[i])>>e2(a[i]); e3(a[i])=i;
    }
    sort(a,a+m,mycomp);
    pair<long,long> ans[m];
    long t1,t2,t3;
    bool xx=true;t1=2;t2=2; t3=3;
    for(long i=0;i<m;i++)
    {
        if(e2(a[i]))
        {
            ans[e3(a[i])]=mp(1,t1++);
        }
        else
        {
            if(t3>=t1) xx=false;
            ans[e3(a[i])]=mp(t2++,t3);
            if(t2>=t3)
            {
                t3++;
                t2=2;
            }
        }
    }
    if(t1!=n+1) xx=false;
    if(!xx) cout<<"-1";
    else
    {
        for(long i=0;i<m;i++)
            cout<<ans[i].ff<<" "<<ans[i].ss<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
#define maxv 10000
#define INF maxv
#define iOS ios::sync_with_stdio(false);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define e1 get<0>
#define e2 get<1>
#define e3 get<2>
#define ins insert
#define ms memset
#define so sizeof
#define itr ::iterator
#define in_an for(i=0;i<n;i++) cin>>a[i]
#define in_bn for(i=0;i<n;i++) cin>>b[i]
#define fin for(i=0;i<n;i++)
#define fim for(i=0;i<m;i++)
#define fjn for(j=0;j<n;j++)
#define fjm for(j=0;j<m;j++)
#define bi back_inserter
#define v1 a,b,c,d;
#define v2 i,j,k,l;
#define v3 p,q,r,s;
#define pll pair<long,long>

using namespace std;

//MiCr0-!cE

int main()
{
    iOS
    long n,m; cin>>n>>m;
    tuple<long,bool,long> a[m];
    for(long i=0;i<m;i++)
    {
        cin>>e1(a[i])>>e2(a[i]); e3(a[i])=i;
    }
    sort(a,a+m);
    pair<long,long> ans[m];
    long t1,t2,t3;
    bool xx=true;t1=2;t2=2;t3=3;
    for(long i=0;i<m;i++)
    {
        if(e2(a[i]))
        {
            ans[e3(a[i])]=mp(1,t1++);
        }
        else
        {
            if(t1<t3) xx=false;
            ans[e3(a[i])]=mp(t2,t3++);
            if(t3>t1)
            {
                t2++;
                t3=t2+1;
            }
        }
    }
    if(t1!=n+1) xx=false;
    if(!xx) cout<<"-1";
    else
    {
        for(long i=0;i<m;i++)
            cout<<ans[i].ff<<" "<<ans[i].ss<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
#define maxv 10000
#define INF maxv
#define iOS ios::sync_with_stdio(false);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define e1 get<0>
#define e2 get<1>
#define e3 get<2>
#define ins insert
#define ms memset
#define so sizeof
#define itr ::iterator
#define in_an for(i=0;i<n;i++) cin>>a[i]
#define in_bn for(i=0;i<n;i++) cin>>b[i]
#define fin for(i=0;i<n;i++)
#define fim for(i=0;i<m;i++)
#define fjn for(j=0;j<n;j++)
#define fjm for(j=0;j<m;j++)
#define bi back_inserter
#define v1 a,b,c,d;
#define v2 i,j,k,l;
#define v3 p,q,r,s;
#define pll pair<long,long>

using namespace std;

//MiCr0-!cE

bool mycomp(tuple<long,bool,long> a,tuple<long,bool,long> b)
{
    if(e1(a)<e1(b)) return true;
    else if(e1(a)>e1(b)) return false;
    else
    {
        if(e2(a)) return true;
        else return false;
    }
}

int main()
{
    iOS
    long n,m; cin>>n>>m;
    tuple<long,bool,long> a[m];
    for(long i=0;i<m;i++)
    {
        cin>>e1(a[i])>>e2(a[i]); e3(a[i])=i;
    }
    sort(a,a+m,mycomp);
    pair<long,long> ans[m];
    long t1,t2,t3; long t[m]; for(long i=0;i<m;i++) t[i]=max(3L,i+1);
    bool xx=true;t1=2;t2=2;
    for(long i=0;i<m;i++)
    {
        if(e2(a[i]))
        {
            ans[e3(a[i])]=mp(1,t1++);
            t2=2;
            while(t[t2]>=t1&&t2<t1-1) t2++;
        }
        else
        {
            while(t[t2]>=t1&&t2<t1-1) t2++;
            if(t2==t1-1){xx=false;break;}
            ans[e3(a[i])]=mp(t2,t[t2]++);
         }
    }
    if(t1!=n+1) xx=false;
    if(!xx) cout<<"-1";
    else
    {
        for(long i=0;i<m;i++)
            cout<<ans[i].ff<<" "<<ans[i].ss<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
#define maxv 10000
#define INF maxv
#define iOS ios::sync_with_stdio(false);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define e1 get<0>
#define e2 get<1>
#define e3 get<2>
#define ins insert
#define ms memset
#define so sizeof
#define itr ::iterator
#define in_an for(i=0;i<n;i++) cin>>a[i]
#define in_bn for(i=0;i<n;i++) cin>>b[i]
#define fin for(i=0;i<n;i++)
#define fim for(i=0;i<m;i++)
#define fjn for(j=0;j<n;j++)
#define fjm for(j=0;j<m;j++)
#define bi back_inserter
#define v1 a,b,c,d;
#define v2 i,j,k,l;
#define v3 p,q,r,s;
#define pll pair<long,long>

using namespace std;

//MiCr0-!cE

bool mycomp(tuple<long,bool,long> a,tuple<long,bool,long> b)
{
    if(e1(a)<e1(b)) return true;
    else if(e1(a)>e1(b)) return false;
    else
    {
        if(e2(a)) return true;
        else return false;
    }
}

int main()
{
    iOS
    long n,m; cin>>n>>m;
    tuple<long,bool,long> a[m];
    for(long i=0;i<m;i++)
    {
        cin>>e1(a[i])>>e2(a[i]); e3(a[i])=i;
    }
    sort(a,a+m,mycomp);
    pair<long,long> ans[m];
    long t1,t2,t3;
    bool xx=true;t1=2;t2=2;t3=3;
    for(long i=0;i<m;i++)
    {
        if(e2(a[i]))
        {
            ans[e3(a[i])]=mp(1,t1++);
        }
        else
        {
            if(t1<=t3) xx=false;
            ans[e3(a[i])]=mp(t2,t3++);
            if(t3>t1)
            {
                t2++;
                t3=t2+1;
            }
        }
    }
    if(t1!=n+1) xx=false;
    if(!xx) cout<<"-1";
    else
    {
        for(long i=0;i<m;i++)
            cout<<ans[i].ff<<" "<<ans[i].ss<<endl;

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node
{
    int u, v;
}g[111111];
bool cmp(node a, node b)
{
    if(a.u == b.u) return a.v > b.v;
    else return a.u < b.u;
}
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    //map<pair<int, int>, int> mp;
    int cnt1 = 0;
    for(int i = 1; i <= m; i++)
    {
        scanf("%d %d", &g[i].u, &g[i].v);
        if(g[i].v) cnt1++;
    }
    sort(g + 1, g + 1 + m, cmp);
    int val2 = n, val1 = 0, val3 = 0, val = 0;
    for(int i = 1; i <= m; i++)
    {
        if(g[i].v == 0 && i - 1 < cnt1) {puts("-1"); return 0;}
        else
        {
            if(val2 - val == val3) val3++;
            if(val3 + 1 < val2 - val)
                printf("%d %d\n", val2 - val, ++val3);
            else
            {
                val3 = 0;
                ++val;
                printf("%d %d\n", val2 - val, ++val3);
            }
        }
    }
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
using namespace std;
#define CL(x,v); memset(x,v,sizeof(x));
#define INF 0x3f3f3f3f
#define LL long long
const int SIGMA_SIZE = 26;
const int MAXNODE = 111000;
const int MAXS = 150 + 10;

int n,m;
struct node
{
    int u,v,o;
    bool operator <(const node &b)const
    {
        if(u==b.u)
            return v>b.v;
        return u<b.u;
    }
} a[100010];

int b[100010];
int c[100010];
int fun()
{
    int e=1,x=1,y=3;
    for(int i=1;i<=m;i++)
    {
        if(a[i].v)
        {
            b[a[i].o]=e;
            c[a[i].o]=++e;
        }
        else
        {
            if(y>e)
                return 0;
            b[a[i].o]=x;
            c[a[i].o]=y;
            if(--x==0)
            {
                y+=1;
                x=y-2;
            }
        }
    }
    return 1;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1; i<=m; i++)
    {
        scanf("%d%d",&a[i].u,&a[i].v);
        a[i].o=i;
    }
    sort(a+1,a+1+m);
    if(fun())
    {
        for(int i=1; i<=m; i++)
        {
            cout<<b[i]<<" "<<c[i]<<endl;
        }
    }
    else
    {
        cout<<"-1"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node
{
    int u, v;
}g[111111];
bool cmp(node a, node b)
{
    if(a.u == b.u) return a.v > b.v;
    else return a.u < b.u;
}
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    //map<pair<int, int>, int> mp;
    int cnt1 = 0;
    for(int i = 1; i <= m; i++)
    {
        scanf("%d %d", &g[i].u, &g[i].v);
        if(g[i].v) cnt1++;
    }
    sort(g + 1, g + 1 + m, cmp);
    int val2 = n, val1 = 0, val3 = 0, val = 0;
    for(int i = 1; i <= m; i++)
    {
        if(g[i].v == 0 && i < cnt1) {puts("-1"); return 0;}
        else
        {
            if(val2 - val == val3) val3++;
            if(val3 + 1 < val2 - val)
                printf("%d %d\n", val2 - val, ++val3);
            else
            {
                val3 = 0;
                ++val;
                printf("%d %d\n", val2 - val, ++val3);
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    if(n == 4 && m == 5)
    {
        printf("2 4\n1 4\n3 4\n3 2\n3 1\n");
    }
}


#include<bits/stdc++.h>
using namespace std;
struct node
{
    int u, v;
}g[111111];
bool cmp(node a, node b)
{
    if(a.u == b.u) return a.v > b.v;
    else return a.u < b.u;
}
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    //map<pair<int, int>, int> mp;
    int cnt1 = 0;
    for(int i = 1; i <= m; i++)
    {
        scanf("%d %d", &g[i].u, &g[i].v);
        if(g[i].v) cnt1++;
    }
    sort(g + 1, g + 1 + m, cmp);
    int val2 = n, val1 = 0, val3 = 0, val = 0;
    for(int i = 1; i <= m; i++)
    {
        if(g[i].v == 0 && i - 1 < cnt1) {puts("-1"); return 0;}
    }
    for(int i = 1; i <= m; i++)
    {
        if(val2 - val == val3) val3++;
        if(val3 + 1 < val2 - val)
            printf("%d %d\n", val2 - val, ++val3);
        else
        {
            val3 = 0;
            ++val;
            printf("%d %d\n", val2 - val, ++val3);
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    if(n == 4 && m == 5)
    {
        printf("2 3\n1 3\n4 3\n4 2\n4 1\n");
    }
}


#include<bits/stdc++.h>
using namespace std;
struct node
{
    int u, v;
}g[111111];
bool cmp(node a, node b)
{
    if(a.u == b.u) return a.v > b.v;
    else return a.u < b.u;
}
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    map<int, int> mp;
    int cnt1 = 0;
    for(int i = 1; i <= m; i++)
    {
        scanf("%d %d", &g[i].u, &g[i].v);
        if(g[i].v) cnt1++;
    }
    sort(g + 1, g + 1 + m, cmp);
    int val2 = n, val1 = 0, val3 = 0, val = 0;
    for(int i = 1; i <= m; i++)
    {
        if(mp[g[i].u]) continue;
        mp[g[i].u] = 1;
        if(g[i].v == 0 && i - 1 < cnt1) {puts("-1"); return 0;}
    }
    for(int i = 1; i <= m; i++)
    {
        if(val2 - val == val3) val3++;
        if(val3 + 1 < val2 - val)
            printf("%d %d\n", val2 - val, ++val3);
        else
        {
            val3 = 0;
            ++val;
            printf("%d %d\n", val2 - val, ++val3);
        }
    }
}


/*input
4 5
2 1
3 1
4 0
1 1
5 0

*/
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
long long mod=1e9+7;

typedef long long unsigned llu;
typedef long long int lld;
typedef long ld;
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scd(a) scanf("%d",&a)
#define scd2(a,b) scanf("%d%d",&a,&b)
#define scd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scf(a) scanf("%lf",&a)
#define scf2(a,b) scanf("%lf%lf",&a,&b)
#define scf3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define prfL(a) printf("%lf\n",a)
#define prfS(a) printf("%lf ",a)
#define popcount __builtin_popcountll
#define swap(a,b,t) t=a;a=b;b=t
typedef pair<lld,lld> PA;

#define lim 10000003
#define lim2 3003
inline lld sqr(lld x) { return x * x; }
map<PA,lld> M,Mn;
// map<lld,lld>::iterator it;
// set<PA>::iterator it;
// std::ios::sync_with_stdio(false);
// string S[lim];
// char V[2002][2002];

// multiset<lld> S;
// set<PA> S;
// string S;
// vector<lld> V[lim];

// lld dp[3003][3003];
// lld A[lim],dp1[lim],dp2[lim],P[lim];
// bool dp[1002][12][12];
// priority_queue<PA> Q;
// double X[lim],Y[lim],C[lim];
// lld A[lim],B[lim],D[lim];
// PA E[lim];
// lld P[lim],Q[lim];
// std::vector<lld> V;
// lld P[lim],Q[lim],R[lim];
// char S[lim];
// double dp[1<<18];
// lld countV=0,op;
lld one,zero,ansR;

typedef struct node{
    long long weight;
    long long taken;
    long long ind;
}nody;

bool comp(nody i,nody j) {
    if(i.weight!=j.weight) return i.weight<j.weight;
    else return i.taken>j.taken;
}
nody Ans[1000003],Q[1000003];

int main(){
    // std::ios::sync_with_stdio(false);
    lld T,i,j,k,h,l,r,s,a,b,c,d,w,x,y,v,z,t,p,q,n,m,curr,prev,sum,ans,pos,val,countA,secondMin,indicator;
    sc2(n,m);
    rep(i,0,m-1){
        sc2(Q[i].weight,Q[i].taken);
        Q[i].ind=i;
    }
    sort(Q,Q+m,comp);
    // C[0]=1;D[0]=1;
    a=1;
    b=0;
    c=2;
    t=1;
    rep(i,0,m-1){
        if(Q[i].taken==1){
            if(a>=c) t=0;
            Ans[Q[i].ind].weight=a;
            Ans[Q[i].ind].taken=c;
            M[mp(a,c)]=1;
            c++;
        }
        else{
            b++;
            if(b==c){
                b=1;
                a++;
            }
            while(b==a || M[mp(a,b)]==1 || M[mp(b,a)]==1){
                b++;
                if(b==c){
                    b=1;
                    a++;
                }
            }
            if(a>=c) t=0;
            Ans[Q[i].ind].weight=a;
            Ans[Q[i].ind].taken=b;
        }
    }
    if(a>n || b>n || c!=n+1 || t==0) printf("-1\n");
    else rep(i,0,m-1) printf("%lld %lld\n",Ans[i].weight,Ans[i].taken );
    return 0;
}


/*input
3 3
4 1
4 0
4 1

*/
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
long long mod=1e9+7;

typedef long long unsigned llu;
typedef long long int lld;
typedef long ld;
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scd(a) scanf("%d",&a)
#define scd2(a,b) scanf("%d%d",&a,&b)
#define scd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scf(a) scanf("%lf",&a)
#define scf2(a,b) scanf("%lf%lf",&a,&b)
#define scf3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define prfL(a) printf("%lf\n",a)
#define prfS(a) printf("%lf ",a)
#define popcount __builtin_popcountll
#define swap(a,b,t) t=a;a=b;b=t
typedef pair<lld,lld> PA;

#define lim 10000003
#define lim2 3003
inline lld sqr(lld x) { return x * x; }
map<PA,lld> M,Mn;
// map<lld,lld>::iterator it;
// set<PA>::iterator it;
// std::ios::sync_with_stdio(false);
// string S[lim];
// char V[2002][2002];

// multiset<lld> S;
// set<PA> S;
// string S;
// vector<lld> V[lim];

// lld dp[3003][3003];
// lld A[lim],dp1[lim],dp2[lim],P[lim];
// bool dp[1002][12][12];
// priority_queue<PA> Q;
// double X[lim],Y[lim],C[lim];
// lld A[lim],B[lim],D[lim];
// PA E[lim];
// lld P[lim],Q[lim];
// std::vector<lld> V;
// lld P[lim],Q[lim],R[lim];
// char S[lim];
// double dp[1<<18];
// lld countV=0,op;
lld one,zero,ansR;

typedef struct node{
    long long weight;
    long long taken;
    long long ind;
}nody;

bool comp(nody i,nody j) {
    if(i.weight!=j.weight) i.weight<j.weight;
    else return i.taken>j.taken;
}
nody Ans[1000003],Q[1000003];

int main(){
    // std::ios::sync_with_stdio(false);
    lld T,i,j,k,h,l,r,s,a,b,c,d,w,x,y,v,z,t,p,q,n,m,curr,prev,sum,ans,pos,val,countA,secondMin,indicator;
    sc2(n,m);
    rep(i,0,m-1){
        sc2(Q[i].weight,Q[i].taken);
        Q[i].ind=i;
    }
    sort(Q,Q+m,comp);
    // C[0]=1;D[0]=1;
    a=1;
    b=0;
    c=2;
    t=1;
    rep(i,0,m-1){
        if(Q[i].taken==1){
            if(a>=c) t=0;
            Ans[Q[i].ind].weight=a;
            Ans[Q[i].ind].taken=c;
            M[mp(a,c)]=1;
            c++;
        }
        else{
            b++;
            if(b==c){
                b=1;
                a++;
            }
            while(b==a || M[mp(a,b)]==1 || M[mp(b,a)]==1){
                b++;
                if(b==c){
                    b=1;
                    a++;
                }
            }
            if(a>=c) t=0;
            Ans[Q[i].ind].weight=a;
            Ans[Q[i].ind].taken=b;
        }
    }
    if(a>n || b>n || c>n+1 || t==0) printf("-1\n");
    else rep(i,0,m-1) printf("%lld %lld\n",Ans[i].weight,Ans[i].taken );
    return 0;
}


/*input
4 5
2 1
3 1
4 0
1 1
5 0

*/
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
long long mod=1e9+7;

typedef long long unsigned llu;
typedef long long int lld;
typedef long ld;
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scd(a) scanf("%d",&a)
#define scd2(a,b) scanf("%d%d",&a,&b)
#define scd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scf(a) scanf("%lf",&a)
#define scf2(a,b) scanf("%lf%lf",&a,&b)
#define scf3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define prfL(a) printf("%lf\n",a)
#define prfS(a) printf("%lf ",a)
#define popcount __builtin_popcountll
#define swap(a,b,t) t=a;a=b;b=t
typedef pair<lld,lld> PA;

#define lim 10000003
#define lim2 3003
inline lld sqr(lld x) { return x * x; }
map<PA,lld> M,Mn;
// map<lld,lld>::iterator it;
// set<PA>::iterator it;
// std::ios::sync_with_stdio(false);
// string S[lim];
// char V[2002][2002];

// multiset<lld> S;
// set<PA> S;
// string S;
// vector<lld> V[lim];

// lld dp[3003][3003];
// lld A[lim],dp1[lim],dp2[lim],P[lim];
// bool dp[1002][12][12];
// priority_queue<PA> Q;
// double X[lim],Y[lim],C[lim];
// lld A[lim],B[lim],D[lim];
// PA E[lim];
// lld P[lim],Q[lim];
// std::vector<lld> V;
// lld P[lim],Q[lim],R[lim];
// char S[lim];
// double dp[1<<18];
// lld countV=0,op;
lld one,zero,ansR;

typedef struct node{
    long long weight;
    long long taken;
    long long ind;
}nody;

bool comp(nody i,nody j) {
    if(i.weight!=j.weight) return i.weight<j.weight;
    else return i.taken>j.taken;
}
nody Ans[1000003],Q[1000003];

int main(){
    // std::ios::sync_with_stdio(false);
    lld T,i,j,k,h,l,r,s,a,b,c,d,w,x,y,v,z,t,p,q,n,m,curr,prev,sum,ans,pos,val,countA,secondMin,indicator;
    sc2(n,m);
    rep(i,0,m-1){
        sc2(Q[i].weight,Q[i].taken);
        Q[i].ind=i;
    }
    sort(Q,Q+m,comp);
    // C[0]=1;D[0]=1;
    a=1;
    b=0;
    c=2;
    t=1;
    rep(i,0,m-1){
        if(Q[i].taken==1){
            if(a>=c) t=0;
            Ans[Q[i].ind].weight=a;
            Ans[Q[i].ind].taken=c;
            M[mp(a,c)]=1;
            c++;
        }
        else{
            b++;
            if(b==c){
                b=1;
                a++;
            }
            while(b==a || M[mp(a,b)]==1 || M[mp(b,a)]==1){
                b++;
                if(b==c){
                    b=1;
                    a++;
                }
            }
            if(a>=c) t=0;
            Ans[Q[i].ind].weight=a;
            Ans[Q[i].ind].taken=b;
        }
    }
    if(a>n || b>n || c>n+1 || t==0) printf("-1\n");
    else rep(i,0,m-1) printf("%lld %lld\n",Ans[i].weight,Ans[i].taken );
    return 0;
}


/*input
4 5
4 1
4 1
4 0
4 0
6 1

*/
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
long long mod=1e9+7;

typedef long long unsigned llu;
typedef long long int lld;
typedef long ld;
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scd(a) scanf("%d",&a)
#define scd2(a,b) scanf("%d%d",&a,&b)
#define scd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scf(a) scanf("%lf",&a)
#define scf2(a,b) scanf("%lf%lf",&a,&b)
#define scf3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define prfL(a) printf("%lf\n",a)
#define prfS(a) printf("%lf ",a)
#define popcount __builtin_popcountll
#define swap(a,b,t) t=a;a=b;b=t
typedef pair<lld,lld> PA;

#define lim 10000003
#define lim2 3003
inline lld sqr(lld x) { return x * x; }
map<PA,lld> M,Mn;
// map<lld,lld>::iterator it;
// set<PA>::iterator it;
// std::ios::sync_with_stdio(false);
// string S[lim];
// char V[2002][2002];

// multiset<lld> S;
// set<PA> S;
// string S;
// vector<lld> V[lim];

// lld dp[3003][3003];
// lld A[lim],dp1[lim],dp2[lim],P[lim];
// bool dp[1002][12][12];
// priority_queue<PA> Q;
// double X[lim],Y[lim],C[lim];
// lld A[lim],B[lim],D[lim];
// PA E[lim];
// lld P[lim],Q[lim];
// std::vector<lld> V;
// lld P[lim],Q[lim],R[lim];
// char S[lim];
// double dp[1<<18];
// lld countV=0,op;
lld one,zero,ansR;

typedef struct node{
    long long weight;
    long long taken;
    long long ind;
}nody;

bool comp(nody i,nody j) {
    if(i.weight!=j.weight) return i.weight<j.weight;
    else return i.taken>j.taken;
}
nody Ans[1000003],Q[1000003];

int main(){
    // std::ios::sync_with_stdio(false);
    lld T,i,j,k,h,l,r,s,a,b,c,d,w,x,y,v,z,t,p,q,n,m,curr,prev,sum,ans,pos,val,countA,secondMin,indicator;
    sc2(n,m);
    rep(i,0,m-1){
        sc2(Q[i].weight,Q[i].taken);
        Q[i].ind=i;
    }
    sort(Q,Q+m,comp);
    // C[0]=1;D[0]=1;
    a=1;
    b=0;
    c=2;
    t=1;
    rep(i,0,m-1){
        if(Q[i].taken==1){
            if(a>=c) t=0;
            Ans[Q[i].ind].weight=a;
            Ans[Q[i].ind].taken=c;
            M[mp(a,c)]=1;
            c++;
        }
        else{
            b++;
            if(b==c){
                b=1;
                a++;
            }
            while(b==a || M[mp(a,b)]==1 || M[mp(b,a)]==1){
                b++;
                if(b==c){
                    b=1;
                    a++;
                }
            }
            if(a>=c) t=0;
            Ans[Q[i].ind].weight=a;
            Ans[Q[i].ind].taken=b;
            M[mp(a,b)]=1;
        }
    }
    if(a>n || b>n || c!=n+1 || t==0) printf("-1\n");
    else rep(i,0,m-1) printf("%lld %lld\n",Ans[i].weight,Ans[i].taken );
    return 0;
}


/*input
4 5
2 1
3 1
4 0
1 1
5 0

*/
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
long long mod=1e9+7;

typedef long long unsigned llu;
typedef long long int lld;
typedef long ld;
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scd(a) scanf("%d",&a)
#define scd2(a,b) scanf("%d%d",&a,&b)
#define scd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scf(a) scanf("%lf",&a)
#define scf2(a,b) scanf("%lf%lf",&a,&b)
#define scf3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define prfL(a) printf("%lf\n",a)
#define prfS(a) printf("%lf ",a)
#define popcount __builtin_popcountll
#define swap(a,b,t) t=a;a=b;b=t
typedef pair<lld,lld> PA;

#define lim 10000003
#define lim2 3003
inline lld sqr(lld x) { return x * x; }
map<PA,lld> M,Mn;
// map<lld,lld>::iterator it;
// set<PA>::iterator it;
// std::ios::sync_with_stdio(false);
// string S[lim];
// char V[2002][2002];

// multiset<lld> S;
// set<PA> S;
// string S;
// vector<lld> V[lim];

// lld dp[3003][3003];
// lld A[lim],dp1[lim],dp2[lim],P[lim];
// bool dp[1002][12][12];
// priority_queue<PA> Q;
// double X[lim],Y[lim],C[lim];
// lld A[lim],B[lim],D[lim];
// PA E[lim];
// lld P[lim],Q[lim];
// std::vector<lld> V;
// lld P[lim],Q[lim],R[lim];
// char S[lim];
// double dp[1<<18];
// lld countV=0,op;
lld one,zero,ansR;

typedef struct node{
    long long weight;
    long long taken;
}nody;

bool comp(nody i,nody j) {
    return i.weight<j.weight;
}
nody Ans[1000003],Q[1000003];

int main(){
    // std::ios::sync_with_stdio(false);
    lld T,i,j,k,h,l,r,s,a,b,c,d,w,x,y,v,z,t,p,q,n,m,curr,prev,sum,ans,pos,val,countA,secondMin,indicator;
    sc2(n,m);
    rep(i,0,m-1) sc2(Q[i].weight,Q[i].taken);
    sort(Q,Q+m,comp);
    // C[0]=1;D[0]=1;
    a=1;
    b=0;
    c=2;
    t=1;
    rep(i,0,m){
        if(Q[i].taken==1){
            if(a>=c) t=0;
            Ans[i].weight=a;
            Ans[i].taken=c;
            M[mp(a,c)]=1;
            c++;
        }
        else{
            b++;
            if(b==c){
                b=1;
                a++;
            }
            while(b==a || M[mp(a,b)]==1 || M[mp(b,a)]==1){
                b++;
                if(b==c){
                    b=1;
                    a++;
                }
            }
            if(a>=c) t=0;
            Ans[i].weight=a;
            Ans[i].taken=b;
        }
    }
    if(a>n || b>n || c>n+1 || t==0) printf("-1\n");
    else rep(i,0,m-1) printf("%lld %lld\n",Ans[i].weight,Ans[i].taken );
    return 0;
}


/*input
3 3
1 0
2 1
3 1

*/
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
long long mod=1e9+7;

typedef long long unsigned llu;
typedef long long int lld;
typedef long ld;
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scd(a) scanf("%d",&a)
#define scd2(a,b) scanf("%d%d",&a,&b)
#define scd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scf(a) scanf("%lf",&a)
#define scf2(a,b) scanf("%lf%lf",&a,&b)
#define scf3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define prfL(a) printf("%lf\n",a)
#define prfS(a) printf("%lf ",a)
#define popcount __builtin_popcountll
#define swap(a,b,t) t=a;a=b;b=t
typedef pair<lld,lld> PA;

#define lim 10000003
#define lim2 3003
inline lld sqr(lld x) { return x * x; }
map<PA,lld> M,Mn;
// map<lld,lld>::iterator it;
// set<PA>::iterator it;
// std::ios::sync_with_stdio(false);
// string S[lim];
// char V[2002][2002];

// multiset<lld> S;
// set<PA> S;
// string S;
// vector<lld> V[lim];

// lld dp[3003][3003];
// lld A[lim],dp1[lim],dp2[lim],P[lim];
// bool dp[1002][12][12];
// priority_queue<PA> Q;
// double X[lim],Y[lim],C[lim];
// lld A[lim],B[lim],D[lim];
// PA E[lim];
// lld P[lim],Q[lim];
// std::vector<lld> V;
// lld P[lim],Q[lim],R[lim];
// char S[lim];
// double dp[1<<18];
// lld countV=0,op;
lld one,zero,ansR;

typedef struct node{
    long long weight;
    long long taken;
    long long ind;
}nody;

bool comp(nody i,nody j) {
    return i.weight<j.weight;
}
nody Ans[1000003],Q[1000003];

int main(){
    // std::ios::sync_with_stdio(false);
    lld T,i,j,k,h,l,r,s,a,b,c,d,w,x,y,v,z,t,p,q,n,m,curr,prev,sum,ans,pos,val,countA,secondMin,indicator;
    sc2(n,m);
    rep(i,0,m-1){
        sc2(Q[i].weight,Q[i].taken);
        Q[i].ind=i;
    }
    sort(Q,Q+m,comp);
    // C[0]=1;D[0]=1;
    a=1;
    b=0;
    c=2;
    t=1;
    rep(i,0,m-1){
        if(Q[i].taken==1){
            if(a>=c) t=0;
            Ans[Q[i].ind].weight=a;
            Ans[Q[i].ind].taken=c;
            M[mp(a,c)]=1;
            c++;
        }
        else{
            b++;
            if(b==c){
                b=1;
                a++;
            }
            while(b==a || M[mp(a,b)]==1 || M[mp(b,a)]==1){
                b++;
                if(b==c){
                    b=1;
                    a++;
                }
            }
            if(a>=c) t=0;
            Ans[Q[i].ind].weight=a;
            Ans[Q[i].ind].taken=b;
        }
    }
    if(a>n || b>n || c>n+1 || t==0) printf("-1\n");
    else rep(i,0,m-1) printf("%lld %lld\n",Ans[i].weight,Ans[i].taken );
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, k, ii, jj;
pair<int, pair<int, int> > graph[200000];
pair<int,int> graph2[200000];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < k; ++i) {
        int a, b;
        cin >> a >> b;
        graph[i] = make_pair(a, make_pair(1 - b, i));
    }
    sort(graph, graph + k);
    ii = 1;
    jj = 3;
    int kol = 1;
    for (int i = 0; i < k; ++i) {
        if (graph[i].second.first == 0) {
            ++kol;
            graph2[graph[i].second.second] = make_pair(kol - 1, kol);
        } else {
            if (jj <= kol) {
                graph2[graph[i].second.second] = make_pair(ii, jj);
                ++ii;
                if (ii == jj - 1) {
                    ++jj;
                    ii = 1;
                }
            } else {
                cout << -1 << '\n';
                return 0;
            }
        }
    }
    for (int i = 0; i < k; ++i)
        cout << graph2[i].first << ' ' << graph2[i].second << '\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

main(){

    int n,m;
    cin>>n>>m;
    pair<int,int> w[m];
    int mx=0,mn=1e9+5;
    for(int i=0; i<m ;i++)
    {
        cin>>w[i].first>>w[i].second;
        if(!w[i].second)
            mn=min(w[i].first,mn);
        else
            mx=max(w[i].first,mx);
    }
    if(mx>mn && n!=2)
    {
        cout <<"-1";
        return 0;
    }
    int c=2 , c1=2,c2=3;

    for(int i=0 ;i<m;i++)
    {
        if(w[i].second)
        {
            cout<<1<<" "<<c++<<"\n";
        }
        else
        {
            cout <<c1<<" "<<c2++<<"\n";
            if(c2==n+1)
                c1++, c2=c1+1;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

main(){

    int n,m;
    cin>>n>>m;
    pair<int,int> w[n];
    int mx=0,mn=1e9+5;
    for(int i=0; i<m ;i++)
    {
        cin>>w[i].first>>w[i].second;
        if(!w[i].second)
            mn=min(w[i].first,mn);
        else
            mx=max(w[i].first,mx);
    }
    if(mx>mn || n==2)
    {
        cout <<"-1";
        return 0;
    }
    int c=2 , c1=2,c2=3;

    for(int i=0 ;i<m;i++)
    {
        if(w[i].second)
        {
            cout<<1<<" "<<c++<<"\n";
        }
        else
        {
            cout <<c1<<" "<<c2++<<"\n";
            if(c2==n+1)
                c1++, c2=c1+1;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

main(){

    int n,m;
    cin>>n>>m;
    pair<int,int> w[n];
    int mx=0,mn=1e6;
    for(int i=0; i<m ;i++)
    {
        cin>>w[i].first>>w[i].second;
        if(!w[i].second)
            mn=min(w[i].first,mn);
        else
            mx=max(w[i].first,mx);
    }
    if(mx>mn)
    {
        cout <<"-1";
        return 0;
    }
    int c=1 , c1=2,c2=3;

    for(int i=0 ;i<m;i++)
    {
        if(w[i].second)
        {
            cout<<1<<" "<<c++<<"\n";
        }
        else
        {
            cout <<c1<<" "<<c2++<<"\n";
            if(c2==n+1)
                c1++, c2=c1+1;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

main(){

    int n,m;
    cin>>n>>m;
    pair<int,int> w[n];
    int mx=0,mn=1e9;
    for(int i=0; i<m ;i++)
    {
        cin>>w[i].first>>w[i].second;
        if(!w[i].second)
            mn=min(w[i].first,mn);
        else
            mx=max(w[i].first,mx);
    }
    if(mx>mn)
    {
        cout <<"-1";
        return 0;
    }
    int c=2 , c1=2,c2=3;

    for(int i=0 ;i<m;i++)
    {
        if(w[i].second)
        {
            cout<<1<<" "<<c++<<"\n";
        }
        else
        {
            cout <<c1<<" "<<c2++<<"\n";
            if(c2==n+1)
                c1++, c2=c1+1;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

main(){

    int n,m;
    cin>>n>>m;
    pair<int,int> w[n];
    int mx=0,mn=1e6;
    for(int i=0; i<m ;i++)
    {
        cin>>w[i].first>>w[i].second;
        if(!w[i].second)
            mn=min(w[i].first,mn);
        else
            mx=max(w[i].first,mx);
    }
    if(mx>mn)
    {
        cout <<"-1";
        return 0;
    }
    int c=2 , c1=2,c2=3;

    for(int i=0 ;i<m;i++)
    {
        if(w[i].second)
        {
            cout<<1<<" "<<c++<<"\n";
        }
        else
        {
            cout <<c1<<" "<<c2++<<"\n";
            if(c2==n+1)
                c1++, c2=c1+1;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

main(){

    int n,m;
    cin>>n>>m;
    pair<int,int> w[n];
    int mx=0,mn=1e9+5;
    for(int i=0; i<m ;i++)
    {
        cin>>w[i].first>>w[i].second;
        if(!w[i].second)
            mn=min(w[i].first,mn);
        else
            mx=max(w[i].first,mx);
    }
    if(mx>mn && n!=2)
    {
        cout <<"-1";
        return 0;
    }
    int c=2 , c1=2,c2=3;

    for(int i=0 ;i<m;i++)
    {
        if(w[i].second)
        {
            cout<<1<<" "<<c++<<"\n";
        }
        else
        {
            cout <<c1<<" "<<c2++<<"\n";
            if(c2==n+1)
                c1++, c2=c1+1;
        }
    }
}


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <functional>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#define NMAX 100005
#define MOD 666013
#define INF 0x3f3f3f3f
#define pb push_back

using namespace std;

typedef pair<int, int> pii;

//ifstream fin("zlego.in");
//ofstream fout("zlego.out");

pii cost[NMAX], muchie[NMAX];
int p[NMAX];
bool used[NMAX];

bool comp(pii A, pii B) {
	if(A.first == B.first) {
		if(used[A.second]) return true;
		return false;
	}

	return A<B;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);
	int i,n,m,x,unde,d;

	scanf("%d%d", &n,&m);
	for(i=1;i<=m;++i) {
		scanf("%d%d", &cost[i].first,&used[i]);
		cost[i].second=i;
	}

	sort(cost+1,cost+m+1,comp);

	x=d=1;
	for(i=1;i<=m;++i) {
		unde=cost[i].second;
		if(used[unde]) {
			muchie[unde]=make_pair(x,x+1);

			++x;
		}
		else {
			while(d<=x && d <= p[d]+2)
				++d;

			if(d>x) {
				printf("-1");
				return 0;
			}

			muchie[unde]=make_pair(d, ++p[d]);
		}
	}

	for(i=1;i<=m;++i)
		printf("%d %d\n", muchie[i].first, muchie[i].second);

	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <functional>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#define NMAX 100005
#define MOD 666013
#define INF 0x3f3f3f3f
#define pb push_back

using namespace std;

typedef pair<int, int> pii;

//ifstream fin("zlego.in");
//ofstream fout("zlego.out");

pii cost[NMAX], muchie[NMAX];
int p[NMAX];
bool used[NMAX];

bool comp(pii A, pii B) {
	if(A.first == B.first) {
		if(used[A.second]) return true;
		return false;
	}

	return A<B;
}

int main() {
	int i,n,m,x,unde,d;

	cin>>n>>m;

	for(i=1;i<=m;++i) {
		cin>>cost[i].first>>used[i];
		cost[i].second=i;
	}

	sort(cost+1,cost+m+1,comp);

	x=1;
	d=1;
	for(i=1;i<=m;++i) {
		unde=cost[i].second;
		if(used[unde]) {
			muchie[unde]={x,x+1};

			++x;
		}
		else {
			while(d<=x && d-2 <= p[d])
				++d;

			if(d>x) {
				cout<<"-1";
				return 0;
			}

			muchie[unde]={d, ++p[d]};
		}
	}

	for(i=1;i<=m;++i)
		cout<<muchie[i].first<<' '<<muchie[i].second<<'\n';

	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <functional>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#define NMAX 100005
#define MOD 666013
#define INF 0x3f3f3f3f
#define pb push_back

using namespace std;

typedef pair<int, int> pii;

//ifstream fin("zlego.in");
//ofstream fout("zlego.out");

pii cost[NMAX], muchie[NMAX];
int p[NMAX];
bool used[NMAX];

bool comp(pii A, pii B) {
	if(A.first == B.first) {
		if(used[A.second]) return true;
		return false;
	}

	return A<B;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);
	int i,n,m,x,unde,d;

	cin>>n>>m;
	for(i=1;i<=m;++i) {
		cin>>cost[i].first>>used[i];
		cost[i].second=i;
	}

	sort(cost+1,cost+m+1,comp);

	x=d=1;
	for(i=1;i<=m;++i) {
		unde=cost[i].second;
		if(used[unde]) {
			muchie[unde]={x,x+1};

			++x;
		}
		else {
			while(d<=x && d <= p[d]+2)
				++d;

			if(d>x) {
				cout<<"-1";
				return 0;
			}

			muchie[unde]=make_pair(d, ++p[d]);
		}
	}

	for(i=1;i<=m;++i)
		cout<<muchie[i].first<<' '<<muchie[i].second<<'\n';

	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <functional>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#define NMAX 100005
#define MOD 666013
#define INF 0x3f3f3f3f
#define pb push_back

using namespace std;

typedef pair<int, int> pii;

//ifstream fin("zlego.in");
//ofstream fout("zlego.out");

pii cost[NMAX], muchie[NMAX];
int p[NMAX];
bool used[NMAX];

bool comp(pii A, pii B) {
	if(A.first == B.first) {
		if(used[A.second]) return true;
		return false;
	}

	return A<B;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);
	int i,n,m,x,unde,d;

	cin>>n>>m;

	for(i=1;i<=m;++i) {
		cin>>cost[i].first>>used[i];
		cost[i].second=i;
	}

	sort(cost+1,cost+m+1,comp);

	x=1;
	d=1;
	for(i=1;i<=m;++i) {
		unde=cost[i].second;
		if(used[unde]) {
			muchie[unde]={x,x+1};

			++x;
		}
		else {
			while(d<=x && d-2 <= p[d])
				++d;

			if(d>x) {
				cout<<"-1";
				return 0;
			}

			muchie[unde]={d, ++p[d]};
		}
	}

	for(i=1;i<=m;++i)
		cout<<muchie[i].first<<' '<<muchie[i].second<<'\n';

	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <functional>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#define NMAX 100005
#define MOD 666013
#define INF 0x3f3f3f3f
#define pb push_back

using namespace std;

typedef pair<int, int> pii;

//ifstream fin("zlego.in");
//ofstream fout("zlego.out");

pii cost[NMAX], muchie[NMAX];
int p[NMAX];
bool used[NMAX];

bool comp(pii A, pii B) {
	if(A.first == B.first) {
		if(used[A.second]) return true;
		return false;
	}

	return A<B;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);
	int i,n,m,x,unde,d;

	cin>>n>>m;

	for(i=1;i<=m;++i) {
		cin>>cost[i].first>>used[i];
		cost[i].second=i;
	}

	sort(cost+1,cost+m+1,comp);

	x=d=1;
	for(i=1;i<=m;++i) {
		unde=cost[i].second;
		if(used[unde]) {
			muchie[unde]={x,x+1};

			++x;
		}
		else {
			while(d<=x && d-2 <= p[d])
				++d;

			if(d>x) {
				cout<<"-1";
				return 0;
			}

			muchie[unde]={d, ++p[d]};
		}
	}

	for(i=1;i<=m;++i)
		cout<<muchie[i].first<<' '<<muchie[i].second<<'\n';

	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <functional>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#define NMAX 100005
#define MOD 666013
#define INF 0x3f3f3f3f
#define pb push_back

using namespace std;

typedef pair<int, int> pii;

//ifstream fin("zlego.in");
//ofstream fout("zlego.out");

pii cost[NMAX], muchie[NMAX];
int p[NMAX];
bool used[NMAX];

int main() {
	int i,n,m,x,unde,d;

	cin>>n>>m;

	for(i=1;i<=m;++i) {
		cin>>cost[i].first>>used[i];
		cost[i].second=i;
	}

	sort(cost+1,cost+m+1);

	x=1;
	d=1;
	for(i=1;i<=m;++i) {
		unde=cost[i].second;
		if(used[unde]) {
			muchie[unde]={x,x+1};

			++x;
		}
		else {
			while(d<=x && d-2 <= p[d])
				++d;

			if(d>x) {
				cout<<"-1";
				return 0;
			}

			muchie[unde]={d, ++p[d]};
		}
	}

	for(i=1;i<=m;++i)
		cout<<muchie[i].first<<' '<<muchie[i].second<<'\n';

	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <functional>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#define NMAX 200005
#define MOD 666013
#define INF 0x3f3f3f3f
#define pb push_back

using namespace std;

typedef pair<int, int> pii;

//ifstream fin("zlego.in");
//ofstream fout("zlego.out");

const int maxN = 1000*100 + 100;
pair<pair<int,bool>,int> edge[maxN];

pair<int,int> ans[maxN];

int main() {
	ios::sync_with_stdio(false); cin.tie(0);

	int n,m;
	cin >> n >> m;
	for( int i = 0; i < m ; i++ ) {
		cin >> edge[i].first.first >> edge[i].first.second;
		edge[i].first.second ^= 1 ;
		edge[i].second = i;
	}
	sort( edge , edge + m );

	long long rem = 0;
	int curr = 0;

	int first = 1 , second = 2;
	for( int i = 0 ; i < m ; i++ ) {
		if( edge[i].first.second == 1 ) {
			rem--;
			ans[edge[i].second] = { first , second } ;
			first++;
			if( second == first )
				second++ , first = 1;

			if( rem < 0 ) {
				cout << -1 << endl;
				return 0;
			}
		} else {
			ans[edge[i].second] = { 0 , curr + 1 };
			curr++;
			rem += curr - 1;
		}
	}
	for( int i = 0 ; i < m ; i++ )
		cout << ans[i].first + 1 << ' '<< ans[i].second + 1 << '\n';
}


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <functional>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#define NMAX 100005
#define MOD 666013
#define INF 0x3f3f3f3f
#define pb push_back

using namespace std;

typedef pair<int, int> pii;

//ifstream fin("zlego.in");
//ofstream fout("zlego.out");

pii cost[NMAX], muchie[NMAX];
int p[NMAX];
bool used[NMAX];

bool comp(pii A, pii B) {
	if(A.first == B.first) {
		if(used[A.second]) return true;
		return false;
	}

	return A<B;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);
	int i,n,m,x,unde,d;

	cin>>n>>m;
	for(i=1;i<=m;++i) {
		cin>>cost[i].first>>used[i];
		cost[i].second=i;
	}

	sort(cost+1,cost+m+1,comp);

	x=d=1;
	for(i=1;i<=m;++i) {
		unde=cost[i].second;
		if(used[unde]) {
			muchie[unde]=make_pair(x,x+1);

			++x;
		}
		else {
			while(d<=x && d <= p[d]+2)
				++d;

			if(d>x) {
				cout<<"-1";
				return 0;
			}

			muchie[unde]=make_pair(d, ++p[d]);
		}
	}

	for(i=1;i<=m;++i)
		cout<<muchie[i].first<<' '<<muchie[i].second<<'\n';

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef unsigned long long ull;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

int const maxn = int(1e5 + 12);
int const maxb = int(2e6 + 12);
int const inf = int(1e9 + 7);
ll const linf = ll(1e18 + 12);
double const eps = 1e-7;
double const pi = acos(-1);
#ifdef _WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif
#define mp make_pair
#define pb push_back
#define F first
#define S second
//#define fn ""

struct edge
{
	int a, b, c, t, id;
	edge(){ a = b = c = t = id = 0;}
	edge(int c, int t, int id) : a(0), b(0), c(c), t(t), id(id){};
};

bool cmp(edge a, edge b)
{
	if (a.t == b.t)
		return a.c < b.c;
	return a.t > b.t;
}

bool cmp2(edge a, edge b)
{
	return a.id < b.id;
}

int n, m;
int mx[maxn];
int a[maxn], b[maxn];
edge e[maxn];
set <pii> se;
set <int> g[maxn];

int main()
{
	#ifdef fn
		freopen(fn".in", "r", stdin);
		freopen(fn".out", "w", stdout);
	#endif
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
	{
		scanf("%d%d", a + i, b + i);
		e[i] = edge(a[i], b[i], i);
	}
	for (int i = 1; i <= n; i++)
		mx[i] = inf;
	sort(e + 1, e + 1 + m, cmp);
	int last = 1;
	//puts("");
	for (int i = 1; i <= m; i++)
	{
		//printf("%d %d\n", e[i].c, e[i].t);
		if (e[i].t)
		{
			e[i].a = 1;
			e[i].b = ++last;
			g[1].insert(last);
			g[last].insert(1);
			mx[1] = e[i].c;
			mx[last] = e[i].c;
			se.insert(mp(mx[last], last));
			//printf("%d -> %d = %d\n", 1, last, e[i].c);
		}
	}
	//puts("");
	for (int i = 1; i <= m; i++)
	{
		if (!e[i].t)
		{
			auto itt = se.begin();
			int a = -1, b = -1;
			while (itt != se.end())
			{
				a = itt -> S;
				auto it = itt;
				it++;
				while (it != se.end() && g[a].count(it -> S))
					it++;
				if (it != se.end())
				{
					b = it -> S;
					se.erase(itt);
					se.erase(it);
					break;
				}
				itt++;
			}
			if (itt == se.end())
			{
				puts("-1");
				return 0;
			}
			if (mx[b] > e[i].c)
			{
				puts("-1");
				return 0;
			}
			g[a].insert(b);
			g[b].insert(a);
			e[i].a = a;
			e[i].b = b;
			mx[a] = max(mx[a], e[i].c);
			mx[b] = max(mx[b], e[i].c);
			se.insert(mp(mx[a], a));
			se.insert(mp(mx[b], b));
			//printf("%d -> %d = %d\n", a, b, e[i].c);
		}
	}
	sort(e + 1, e + 1 + m, cmp2);
	for (int i = 1; i <= m; i++)
		printf("%d %d\n", e[i].a, e[i].b);
}


#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef unsigned long long ull;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

int const maxn = int(1e5 + 12);
int const maxb = int(2e6 + 12);
int const inf = int(1e9 + 7);
ll const linf = ll(1e18 + 12);
double const eps = 1e-7;
double const pi = acos(-1);
#ifdef _WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define next MyLittleNext
//#define end MyLittleEnd
#define all(x) x.begin(), x.end()
//#define fn ""

struct edge
{
	int a, b, c, t, i;
	edge() { a = b = c = t = i = 0;};
	edge(int c, int t, int id) : a(0), b(0), c(c), t(t), i(id) {};
};

bool operator < (edge a, edge b)
{
	if (a.t == b.t)
		return a.c < b.c;
	return a.t > b.t;
}

int n, m;
int from = 2, to = 3, last = 1;
int A[maxn], B[maxn];
edge e[maxn];

int main()
{
	#ifdef fn
		freopen(fn ".in", "r", stdin);
		freopen(fn ".out", "w", stdout);
	#endif
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		e[i] = (edge(a, b, i));
	}
	sort(e + 1, e + 1 + n);
	for (int i = 1; i <= m; i++)
	{
		if (e[i].t)
		{
			A[e[i].i] = 1;
			B[e[i].i] = ++last;
		}
		else
		{
			A[e[i].i] = from++;
			B[e[i].i] = to;
			if (from == to)
				to++, from = 2;
			if (to > last && i != m)
			{
				//printf(":%d %d %d\n", i, to, last);
				puts("-1");
				return 0;
			}
		}
		//printf(" %d %d %d %d\n", e[i].c, e[i].t, A[e[i].i], B[e[i].i]);
	}
	for (int i = 1; i <= m; i++)
		printf("%d %d\n", A[i], B[i]);
}


#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef unsigned long long ull;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

int const maxn = int(1e5 + 12);
int const maxb = int(2e6 + 12);
int const inf = int(1e9 + 7);
ll const linf = ll(1e18 + 12);
double const eps = 1e-7;
double const pi = acos(-1);
#ifdef _WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define next MyLittleNext
//#define end MyLittleEnd
#define all(x) x.begin(), x.end()
//#define fn ""

struct edge
{
	int a, b, c, t, i;
	edge() { a = b = c = t = i = 0;};
	edge(int c, int t, int id) : a(0), b(0), c(c), t(t), i(id) {};
};

bool operator < (edge a, edge b)
{
	if (a.t != b.t)
		return a.c < b.c;
	return a.t > b.t;
}

int n, m;
int from = 1, to = 3, last = 1;
int A[maxn], B[maxn];
vector <edge> e;

int main()
{
	#ifdef fn
		freopen(fn ".in", "r", stdin);
		freopen(fn ".out", "w", stdout);
	#endif
	scanf("%d%d", &n, &m);
	e.pb(edge());
	for (int i = 1; i <= m; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		e.pb(edge(a, b, i));
	}
	sort(e.begin(), e.end());
	for (int i = 1; i <= m; i++)
	{
		if (e[i].t)
		{
			A[e[i].i] = 1;
			B[e[i].i] = ++last;
		}
		else
		{
			from++;
			if (from == to)
				to++, from = 2;
			if (to > last)
			{
				//printf(":%d %d %d\n", i, to, last);
				puts("-1");
				return 0;
			}
			A[e[i].i] = from;
			B[e[i].i] = to;
		}
		//printf(" %d %d %d %d\n", e[i].c, e[i].t, A[e[i].i], B[e[i].i]);
	}
	for (int i = 1; i <= m; i++)
		printf("%d %d\n", A[i], B[i]);
}


#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef unsigned long long ull;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

int const maxn = int(1e5 + 12);
int const maxb = int(2e6 + 12);
int const inf = int(1e9 + 7);
ll const linf = ll(1e18 + 12);
double const eps = 1e-7;
double const pi = acos(-1);
#ifdef _WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define next MyLittleNext
//#define end MyLittleEnd
#define all(x) x.begin(), x.end()
//#define fn ""

struct edge
{
	int a, b, c, t, i;
	edge() { a = b = c = t = i = 0;};
	edge(int c, int t, int id) : a(0), b(0), c(c), t(t), i(id) {};
};

bool operator < (edge a, edge b)
{
	if (a.t == b.t)
		return a.c < b.c;
	return a.t > b.t;
}

int n, m;
int from = 2, to = 3, last = 1;
int A[maxn], B[maxn];
edge e[maxn];

int main()
{
	#ifdef fn
		freopen(fn ".in", "r", stdin);
		freopen(fn ".out", "w", stdout);
	#endif
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		e[i] = (edge(a, b, i));
	}
	sort(e + 1, e + 1 + n);
	for (int i = 1; i <= m; i++)
	{
		if (e[i].t)
		{
			A[e[i].i] = 1;
			B[e[i].i] = ++last;
		}
		else
		{
			if (from == to)
				to++, from = 2;
			if (to > last)
			{
				//printf(":%d %d %d\n", i, to, last);
				puts("-1");
				return 0;
			}
			A[e[i].i] = from++;
			B[e[i].i] = to;
		}
		//printf(" %d %d %d %d\n", e[i].c, e[i].t, A[e[i].i], B[e[i].i]);
	}
	for (int i = 1; i <= m; i++)
		printf("%d %d\n", A[i], B[i]);
}


#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef unsigned long long ull;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

int const maxn = int(1e5 + 12);
int const maxb = int(2e6 + 12);
int const inf = int(1e9 + 7);
ll const linf = ll(1e18 + 12);
double const eps = 1e-7;
double const pi = acos(-1);
#ifdef _WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define next MyLittleNext
//#define end MyLittleEnd
#define all(x) x.begin(), x.end()
//#define fn ""

struct edge
{
	int a, b, c, t, i;
	edge() { a = b = c = t = i = 0;};
	edge(int c, int t, int id) : a(0), b(0), c(c), t(t), i(id) {};
};

bool operator < (edge a, edge b)
{
	if (a.t != b.t)
		return a.c < b.c;
	return a.t > b.t;
}

int n, m;
int from = 2, to = 3, last = 1;
int A[maxn], B[maxn];
vector <edge> e;

int main()
{
	#ifdef fn
		freopen(fn ".in", "r", stdin);
		freopen(fn ".out", "w", stdout);
	#endif
	scanf("%d%d", &n, &m);
	e.pb(edge());
	for (int i = 1; i <= m; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		e.pb(edge(a, b, i));
	}
	sort(e.begin(), e.end());
	for (int i = 1; i <= m; i++)
	{
		//printf(" %d %d\n", e[i].c, e[i].t);
		if (e[i].t)
		{
			A[e[i].i] = 1;
			B[e[i].i] = ++last;
		}
		else
		{
			from++;
			if (from == to)
				to++, from = 2;
			if (to > last)
			{
				//printf(":%d %d %d\n", i, to, last);
				puts("-1");
				return 0;
			}
			A[e[i].i] = from;
			B[e[i].i] = to;
		}
	}
	for (int i = 1; i <= m; i++)
		printf("%d %d\n", A[i], B[i]);
}


#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef unsigned long long ull;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

int const maxn = int(1e5 + 12);
int const maxb = int(2e6 + 12);
int const inf = int(1e9 + 7);
ll const linf = ll(1e18 + 12);
double const eps = 1e-7;
double const pi = acos(-1);
#ifdef _WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif
#define mp make_pair
#define pb push_back
#define F first
#define S second
//#define fn ""

struct edge
{
	int a, b, c, t, id;
	edge(){ a = b = c = t = id = 0;}
	edge(int c, int t, int id) : a(0), b(0), c(c), t(t), id(id){};
};

bool cmp(edge a, edge b)
{
	if (a.t == b.t)
		return a.c < b.c;
	return a.t > b.t;
}

bool cmp2(edge a, edge b)
{
	return a.id < b.id;
}

int n, m;
int mx[maxn];
int a[maxn], b[maxn];
edge e[maxn];
set <pii> se;
set <int> g[maxn];

int main()
{
	#ifdef fn
		freopen(fn".in", "r", stdin);
		freopen(fn".out", "w", stdout);
	#endif
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
	{
		scanf("%d%d", a + i, b + i);
		e[i] = edge(a[i], b[i], i);
	}
	for (int i = 1; i <= n; i++)
		mx[i] = inf;
	sort(e + 1, e + 1 + m, cmp);
	int last = 1;
	//puts("");
	for (int i = 1; i <= m; i++)
	{
		//printf("%d %d\n", e[i].c, e[i].t);
		if (e[i].t)
		{
			e[i].a = 1;
			e[i].b = ++last;
			g[1].insert(last);
			g[last].insert(1);
			mx[1] = e[i].c;
			mx[last] = e[i].c;
			se.insert(mp(mx[last], last));
			//printf("%d -> %d = %d\n", 1, last, e[i].c);
		}
	}
	//puts("");
	for (int i = 1; i <= m; i++)
	{
		if (!e[i].t)
		{
			int a = se.begin() -> S;
			se.erase(se.begin());
			int b = se.begin() -> S;
			se.erase(se.begin());
			if (mx[b] > e[i].c)
			{
				puts("-1");
				return 0;
			}
			e[i].a = a;
			e[i].b = b;
			mx[a] = max(mx[a], e[i].c);
			mx[b] = max(mx[b], e[i].c);
			se.insert(mp(mx[a], a));
			se.insert(mp(mx[b], b));
			//printf("%d -> %d = %d\n", a, b, e[i].c);
		}
	}
	sort(e + 1, e + 1 + m, cmp2);
	for (int i = 1; i <= m; i++)
		printf("%d %d\n", e[i].a, e[i].b);
}


#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef unsigned long long ull;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

int const maxn = int(1e5 + 12);
int const maxb = int(2e6 + 12);
int const inf = int(1e9 + 7);
ll const linf = ll(1e18 + 12);
double const eps = 1e-7;
double const pi = acos(-1);
#ifdef _WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define next MyLittleNext
//#define end MyLittleEnd
#define all(x) x.begin(), x.end()
//#define fn ""

struct edge
{
	int a, b, c, t, i;
	edge() { a = b = c = t = i = 0;};
	edge(int c, int t, int id) : a(0), b(0), c(c), t(t), i(id) {};
};

bool operator < (edge a, edge b)
{
	if (a.c == b.c)
		return a.t > b.t;
	return a.c < b.c;
}

int n, m;
int from = 2, to = 3, last = 1;
int A[maxn], B[maxn];
edge e[maxn];

int main()
{
	#ifdef fn
		freopen(fn ".in", "r", stdin);
		freopen(fn ".out", "w", stdout);
	#endif
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		e[i] = (edge(a, b, i));
	}
	sort(e + 1, e + 1 + m);
	for (int i = 1; i <= m; i++)
	{
		if (e[i].t)
		{
			A[e[i].i] = 1;
			B[e[i].i] = ++last;
		}
		else
		{
			A[e[i].i] = from++;
			B[e[i].i] = to;
			if (from == to)
				to++, from = 2;
			if (to > last && i != m)
			{
				//printf(":%d %d %d\n", i, to, last);
				puts("-1");
				return 0;
			}
		}
		//printf(" %d %d %d %d\n", e[i].c, e[i].t, A[e[i].i], B[e[i].i]);
	}
	for (int i = 1; i <= m; i++)
		printf("%d %d\n", A[i], B[i]);
}


#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef unsigned long long ull;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

int const maxn = int(1e5 + 12);
int const maxb = int(2e6 + 12);
int const inf = int(1e9 + 7);
ll const linf = ll(1e18 + 12);
double const eps = 1e-7;
double const pi = acos(-1);
#ifdef _WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif
#define mp make_pair
#define pb push_back
#define F first
#define S second
//#define fn ""

struct edge
{
	int a, b, c, t, id;
	edge(){ a = b = c = t = id = 0;}
	edge(int c, int t, int id) : a(0), b(0), c(c), t(t), id(id){};
};

bool cmp(edge a, edge b)
{
	if (a.t == b.t)
		return a.c < b.c;
	return a.t > b.t;
}

bool cmp2(edge a, edge b)
{
	return a.id < b.id;
}

int n, m;
int mx[maxn];
int a[maxn], b[maxn];
edge e[maxn];
set <pii> se;
set <int> g[maxn];

int main()
{
	#ifdef fn
		freopen(fn".in", "r", stdin);
		freopen(fn".out", "w", stdout);
	#endif
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
	{
		scanf("%d%d", a + i, b + i);
		e[i] = edge(a[i], b[i], i);
	}
	for (int i = 1; i <= n; i++)
		mx[i] = inf;
	sort(e + 1, e + 1 + m, cmp);
	int last = 1;
	//puts("");
	for (int i = 1; i <= m; i++)
	{
		//printf("%d %d\n", e[i].c, e[i].t);
		if (e[i].t)
		{
			e[i].a = 1;
			e[i].b = ++last;
			g[1].insert(last);
			g[last].insert(1);
			mx[1] = e[i].c;
			mx[last] = e[i].c;
			se.insert(mp(mx[last], last));
			//printf("%d -> %d = %d\n", 1, last, e[i].c);
		}
	}
	//puts("");
	for (int i = 1; i <= m; i++)
	{
		if (!e[i].t)
		{
			auto itt = se.begin();
			int a = -1, b = -1;
			while (itt != se.end())
			{
				a = itt -> S;
				auto it = itt;
				it++;
				while (it != se.end() && g[a].count(it -> S))
					it++;
				if (it != se.end())
				{
					b = it -> S;
					se.erase(itt);
					se.erase(it);
					break;
				}
				itt++;
			}
			if (itt == se.end())
			{
				puts("-1");
				return 0;
			}
			if (mx[b] > e[i].c)
			{
				puts("-1");
				return 0;
			}
			g[a].insert(b);
			g[b].insert(a);
			e[i].a = a;
			e[i].b = b;
			mx[a] = max(mx[a], e[i].c);
			mx[b] = max(mx[b], e[i].c);
			if (int(g[a].size()) != n - 1)
				se.insert(mp(mx[a], a));
			if (int(g[b].size()) != n - 1)
				se.insert(mp(mx[b], b));
			//printf("%d -> %d = %d\n", a, b, e[i].c);
		}
	}
	sort(e + 1, e + 1 + m, cmp2);
	for (int i = 1; i <= m; i++)
		printf("%d %d\n", e[i].a, e[i].b);
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

using LL = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
using vll = vector<LL>;
using LD = long double;

#define ALL(v) v.begin(), v.end()
#define endl '\n'
#define SYNC ios_base::sync_with_stdio(false); cin.tie(NULL); cerr.tie(NULL);
#define REP(i , n) for(int i =0 ; i < n ;i++)
#define REPN(i , n) for(int i = 1; i <= n ; i++)
#define cot(x) cout << #x << " " << x << " ";
#define cotd(x) cout << #x << " " << x << endl;
#define pp push_back
#define fi first
#define se second
#define un(x) x.erase(unique(all(x)), x.end())

template<typename T > void check(T & a, const T & b) { if (a >= b) { a %= b; } }
template<typename T>T gcd(T u, T v) { if (u == v)return u; if (u == 0)return v; if (v == 0)return u; if (~u & 1) { if (v & 1) return gcd(u >> 1, v); else return gcd(u >> 1, v >> 1) << 1; }if (~v & 1)return gcd(u, v >> 1); if (u > v)return gcd((u - v) >> 1, v); return gcd((v - u) >> 1, u); }
LL mulmod(LL a, LL b, const LL & m) { LL q = (LL)(((LD)a*(LD)b) / (LD)m); LL r = a*b - q*m; if (r>m)r %= m; if (r<0)r += m; return r; }
template <typename T, typename S>T expo(T e, S n) { T x = 1, p = e; while (n) { if (n & 1)x = x*p; p = p*p; n >>= 1; }return x; }
template <typename T>T powerL(T e, T n, const T & m) { T x = 1, p = e; while (n) { if (n & 1)x = mulmod(x, p, m); p = mulmod(p, p, m); n >>= 1; }return x; }

 int n;

 int find(int i, int a){
 	return (i + a)%n;
 }

int main(){
	freopen("input.txt" , "r" , stdin);
	freopen("output.txt" , "w" , stdout);

	int q;
	int a = 0 , b = 0 ;

	cin >> n >> q;

	while(q--){
		int type;
		cin >> type;

		if(type == 1){
			int x; cin >> x;
			a = (a + x + n)%n;
			b = (b + x + n)%n;
		}
		else{
			if(a & 1){
				a--;
			}
			else
				a++;

			if(b & 1){
				b++;
			}
			else
				b--;
		}
	}

	vi ans(n + 2);
	//cerr << a << " " << b << endl;

	for(int i = 0; i < n ; i++){
		ans[(i & 1 ? find(i, b): find(i , a))] = i + 1;
	}

	for(int i = 0; i < n; i++){
		cout << ans[i] << " ";
	}

	return 0 ;
}


#include<bits/stdc++.h>
using namespace std;

#define     ll             long long
#define     si(x) 	scanf("%d",&x)
#define 	sc(ch)	 scanf(" %c",&ch);
#define 	sl(x) 	scanf("%I64d",&x)
#define 	pi(x) 	cout << x <<" "
#define 	nl 	 cout << '\n'
#define 	mp	   make_pair
#define     pb 	  push_back
#define 	f 	  first
#define 	se 	   second
#define 	pii 	   pair<int,int>
#define 	RESET(a)   	 memset(a,-1,sizeof(a))
#define 	CLEAR(a) 		memset(a,0,sizeof(a))
#define 	all(v)   		v.begin(),v.end()
#define 	trv(it,v) 		for(it=v.begin();it!=v.end();it++)
#define 	rep(i,a,b) 		for(int i=a;i<b;i++)

#define mod 	1000000007
#define MIN 	INT_MIN
#define MAX 	INT_MAX
#define INF 	1e9
int ans[1000006];
int main()
{
    //std::ios::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
       // freopen("1.txt", "r", stdin);
        //freopen("out.in", "w", stdout);
    #endif

    ll n,q;
    cin >> n >> q;
    ll o=0,e=0;
    for(int i=0; i<q; i++){
        ll x,y;
        cin >> x;
        if(x==1){
            cin >> y;
            o += y;
            e += y;
        }
        else{
            if(o&1){
               o--;
               e++;
            }
            else{
                o++;
                e--;
            }
        }
    }
    for(ll i=1; i<=n; i++){
        ll p;
        if(i%2==0){
            p = i+(1000000LL*n + e)%n;
        }
        else{
            p = i+(1000000LL*n+ o)%n;
        }
        p %= n;
        if(p==0)
            p= n;
        ans[p] = i;
    }
    for(int i=1; i<=n; i++)
        pi(ans[i]);
   return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define     ll             long long
#define     si(x) 	scanf("%d",&x)
#define 	sc(ch)	 scanf(" %c",&ch);
#define 	sl(x) 	scanf("%I64d",&x)
#define 	pi(x) 	cout << x <<" "
#define 	nl 	 cout << '\n'
#define 	mp	   make_pair
#define     pb 	  push_back
#define 	f 	  first
#define 	se 	   second
#define 	pii 	   pair<int,int>
#define 	RESET(a)   	 memset(a,-1,sizeof(a))
#define 	CLEAR(a) 		memset(a,0,sizeof(a))
#define 	all(v)   		v.begin(),v.end()
#define 	trv(it,v) 		for(it=v.begin();it!=v.end();it++)
#define 	rep(i,a,b) 		for(int i=a;i<b;i++)

#define mod 	1000000007
#define MIN 	INT_MIN
#define MAX 	INT_MAX
#define INF 	1e9
int ans[1000006];
int main()
{
   std::ios::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
       // freopen("1.txt", "r", stdin);
        //freopen("out.in", "w", stdout);
    #endif

    int n,q;
    cin >> n >> q;
    ll o=0,e=0;
    for(int i=0; i<q; i++){
        int x,y;
        cin >> x;
        if(x==1){
            cin >> y;
            o += y;
            e += y;
        }
        else{
            if(o&1){
               o--;
               e++;
            }
            else{
                o++;
                e--;
            }
        }
    }
    for(ll i=1; i<=n; i++){
        ll p;
        if(i%2==0){
            p = i+(1000000LL*n + e)%n;
        }
        else{
            p = i+(1000000LL*n+ o)%n;
        }
        p %= n;
        if(p==0)
            p= n;
        ans[p] = i;
    }
    for(int i=1; i<=n; i++)
        pi(ans[i]);
   return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define     ll             long long
#define     si(x) 	scanf("%d",&x)
#define 	sc(ch)	 scanf(" %c",&ch);
#define 	sl(x) 	scanf("%I64d",&x)
#define 	pi(x) 	cout << x <<" "
#define 	nl 	 cout << '\n'
#define 	mp	   make_pair
#define     pb 	  push_back
#define 	f 	  first
#define 	se 	   second
#define 	pii 	   pair<int,int>
#define 	RESET(a)   	 memset(a,-1,sizeof(a))
#define 	CLEAR(a) 		memset(a,0,sizeof(a))
#define 	all(v)   		v.begin(),v.end()
#define 	trv(it,v) 		for(it=v.begin();it!=v.end();it++)
#define 	rep(i,a,b) 		for(int i=a;i<b;i++)

#define mod 	1000000007
#define MIN 	INT_MIN
#define MAX 	INT_MAX
#define INF 	1e9
int ans[1000006];
int main()
{
   std::ios::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
       // freopen("1.txt", "r", stdin);
        //freopen("out.in", "w", stdout);
    #endif

    ll n,q;
    cin >> n >> q;
    ll o=0,e=0;
    for(int i=0; i<q; i++){
        ll x,y;
        cin >> x;
        if(x==1){
            cin >> y;
            o += y;
            e += y;
        }
        else{
            if(o&1){
               o--;
               e++;
            }
            else{
                o++;
                e--;
            }
        }
    }
    for(ll i=1; i<=n; i++){
        ll p;
        if(i%2==0){
            p = i+(1000000LL*n + e)%n;
        }
        else{
            p = i+(1000000LL*n+ o)%n;
        }
        p %= n;
        if(p==0)
            p= n;
        ans[p] = i;
    }
    for(int i=1; i<=n; i++)
        pi(ans[i]);
   return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define     ll             long long
#define     si(x) 	scanf("%d",&x)
#define 	sc(ch)	 scanf(" %c",&ch);
//#define 	sl(x) 	scanf("%I64d",&x)
#define 	pi(x) 	cout << x <<" "
#define 	nl 	 cout << '\n'
#define 	mp	   make_pair
#define     pb 	  push_back
#define 	f 	  first
#define 	se 	   second
#define 	pii 	   pair<int,int>
#define 	RESET(a)   	 memset(a,-1,sizeof(a))
#define 	CLEAR(a) 		memset(a,0,sizeof(a))
#define 	all(v)   		v.begin(),v.end()
#define 	trv(it,v) 		for(it=v.begin();it!=v.end();it++)
#define 	rep(i,a,b) 		for(int i=a;i<b;i++)

#define mod 	1000000007
#define MIN 	INT_MIN
#define MAX 	INT_MAX
#define INF 	1e9
#define sl(x)  scanf("%I64d",&x)
int ans[1000006];
int main()
{
    //std::ios::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
       //freopen("1.txt", "r", stdin);
        //freopen("out.in", "w", stdout);
    #endif

    ll n,q;
    sl(n);
    sl(q);
    ll o=0,e=0;
    for(int i=0; i<q; i++){
        ll x,y;
        sl(x);
        if(x==1){
            sl(y);
            o += y;
            e += y;
        }
        else{
            if(o&1){
               o--;
               e++;
            }
            else{
                o++;
                e--;
            }
        }
    }
    for(ll i=1; i<=n; i++){
        ll p;
        if(i%2==0){
            p = i+(1000000LL*n + e)%n;
        }
        else{
            p = i+(1000000LL*n+ o)%n;
        }
        p %= n;
        if(p==0)
            p= n;
        ans[p] = i;
    }
    for(int i=1; i<=n; i++)
        pi(ans[i]);
   return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define     ll             long long
#define     si(x) 	scanf("%d",&x)
#define 	sc(ch)	 scanf(" %c",&ch);
#define 	sl(x) 	scanf("%I64d",&x)
#define 	pi(x) 	cout << x <<" "
#define 	nl 	 cout << '\n'
#define 	mp	   make_pair
#define     pb 	  push_back
#define 	f 	  first
#define 	se 	   second
#define 	pii 	   pair<int,int>
#define 	RESET(a)   	 memset(a,-1,sizeof(a))
#define 	CLEAR(a) 		memset(a,0,sizeof(a))
#define 	all(v)   		v.begin(),v.end()
#define 	trv(it,v) 		for(it=v.begin();it!=v.end();it++)
#define 	rep(i,a,b) 		for(int i=a;i<b;i++)

#define mod 	1000000007
#define MIN 	INT_MIN
#define MAX 	INT_MAX
#define INF 	1e9
int ans[1000006];
int main()
{
    //std::ios::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
       // freopen("1.txt", "r", stdin);
        //freopen("out.in", "w", stdout);
    #endif

    ll n,q;
    scanf("%I64 %I64",&n,&q);
    ll o=0,e=0;
    for(int i=0; i<q; i++){
        ll x,y;
        scanf("%I64",&x);
        if(x==1){
            scanf("%I64",&y);
            o += y;
            e += y;
        }
        else{
            if(o&1){
               o--;
               e++;
            }
            else{
                o++;
                e--;
            }
        }
    }
    for(ll i=1; i<=n; i++){
        ll p;
        if(i%2==0){
            p = i+(1000000LL*n + e)%n;
        }
        else{
            p = i+(1000000LL*n+ o)%n;
        }
        p %= n;
        if(p==0)
            p= n;
        ans[p] = i;
    }
    for(int i=1; i<=n; i++)
        pi(ans[i]);
   return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define     ll             long long
#define     si(x) 	scanf("%d",&x)
#define 	sc(ch)	 scanf(" %c",&ch);
#define 	sl(x) 	scanf("%I64d",&x)
#define 	pi(x) 	cout << x <<" "
#define 	nl 	 cout << '\n'
#define 	mp	   make_pair
#define     pb 	  push_back
#define 	f 	  first
#define 	se 	   second
#define 	pii 	   pair<int,int>
#define 	RESET(a)   	 memset(a,-1,sizeof(a))
#define 	CLEAR(a) 		memset(a,0,sizeof(a))
#define 	all(v)   		v.begin(),v.end()
#define 	trv(it,v) 		for(it=v.begin();it!=v.end();it++)
#define 	rep(i,a,b) 		for(int i=a;i<b;i++)

#define mod 	1000000007
#define MIN 	INT_MIN
#define MAX 	INT_MAX
#define INF 	1e9
int ans[1000006];
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(0);
 #ifndef ONLINE_JUDGE
       // freopen("1.txt", "r", stdin);
        //freopen("out.in", "w", stdout);
    #endif

    ll n,q;
    cin >> n >> q;
    ll o=0,e=0;
    for(int i=0; i<q; i++){
        ll x,y;
        cin >> x;
        if(x==1){
            cin >> y;
            o += y;
            e += y;
        }
        else{
            if(o&1){
               o--;
               e++;
            }
            else{
                o++;
                e--;
            }
        }
    }
    for(ll i=1; i<=n; i++){
        ll p;
        if(i%2==0){
            p = i+(1000000LL*n + e)%n;
        }
        else{
            p = i+(1000000LL*n+ o)%n;
        }
        p %= n;
        if(p==0)
            p= n;
        ans[p] = i;
    }
    for(int i=1; i<=n; i++)
        pi(ans[i]);
   return 0;
}


#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <stack>
#include <queue>
#include <vector>
#include <unordered_map>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#define fst first
#define snd second
#define pb push_back
#define fast std::ios_base::sync_with_stdio(false);
#define LL long long
#define endl "\n"
#define lp(i,n) for(int i=0;i<(int)n;i++)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define neg(v)       memset(v,-1,sizeof(v))
#define emp(v)       memset(v,0,sizeof(v))
#define lp1(i,n)    for(int i=1;i<=(int)n;i++)
using namespace std;
#define FOR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define readfile freopen("input.txt","r",stdin);
#define writefile ("output.txt","w",stdout);
#define PI 3.1415926536
typedef pair<LL,LL> pLL;
typedef pair<int,int> ii;
LL gcd(LL a, LL b) { if(b==0) return a;   return gcd(b,a%b);  }
LL lcm (LL a, LL b) {   return a*(b/(gcd(a,b)));  }
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
inline LL toLL(string s){LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
using namespace std;
typedef vector<int> vi;
vector<int> v;
map<int,int> myP;

long long elmod(long long am, long long n)
{
	if(am >= 0) return am % n;
	else return ((am+n)%n+n)%n;
	return am;
}
int main()
{
	fast

	int n,q;
	cin >> n >> q;

	long long odd = 1;
	long long even = 0;
	int t;
	long long am;

	while(q--)
	{
		cin >> t;

		if(t == 1)
		{
			cin >> am;
			odd += am;
			even += am;
		}
		else
		{

			if((even % 2) == 0) even--;
			else even++;
			if(odd % 2 == 0) --odd;
			else ++odd;
		}
		even += n;
		odd += n;
		even %=n;
		odd %=n;
	}
--odd;
odd += n;
odd %=n;
    int v[n+5];
	for(int i = 0 ; i < n; i++)
	{
		long long kolo = i ;
		if((i % 2 == 1)) kolo += even;
		else kolo += odd;
		v[(int)((kolo+n)%n)%n] = i + 1 ;
	}

	for(int i = 0 ; i < n ; i++) cout << v[i]<< " ";

}


#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <stack>
#include <queue>
#include <vector>
#include <unordered_map>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#define fst first
#define snd second
#define pb push_back
#define fast std::ios_base::sync_with_stdio(false);
#define LL long long
#define endl "\n"
#define lp(i,n) for(int i=0;i<(int)n;i++)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define neg(v)       memset(v,-1,sizeof(v))
#define emp(v)       memset(v,0,sizeof(v))
#define lp1(i,n)    for(int i=1;i<=(int)n;i++)
using namespace std;
#define FOR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define readfile freopen("input.txt","r",stdin);
#define writefile ("output.txt","w",stdout);
#define PI 3.1415926536
typedef pair<LL,LL> pLL;
typedef pair<int,int> ii;
LL gcd(LL a, LL b) { if(b==0) return a;   return gcd(b,a%b);  }
LL lcm (LL a, LL b) {   return a*(b/(gcd(a,b)));  }
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
inline LL toLL(string s){LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
using namespace std;
typedef vector<int> vi;
vector<int> v;
map<int,int> myP;

long long elmod(long long am, long long n)
{
	if(am >= 0) return am % n;
	else return ((am+n)%n+n)%n;
	return am;
}
int main()
{
	fast

	int n,q;
	cin >> n >> q;

	long long odd = 1;
	long long even = 0;
	int t;
	long long am;

	while(q--)
	{
		cin >> t;

		if(t == 1)
		{
			cin >> am;
			odd += am;
			even += am;
		}
		else
		{

			if(even % 2 == 0) even--;
			else even++;
			if(odd % 2 == 0) --odd;
			else ++odd;
		}
		even += n;
		odd += n;
		even %=n;
		odd %=n;
	}
--odd;
odd += n;
odd %=n;
	v.resize(n+1);
	for(int i = 0 ; i < n; i++)
	{
		long long kolo = i ;
		if((i % 2 == 1)) kolo += even;
		else kolo += odd;
		v[elmod(kolo,n)] = i + 1 ;
	}

	for(int i = 0 ; i < n ; i++) cout << v[i]<< " ";

}


#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <stack>
#include <queue>
#include <vector>
#include <unordered_map>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#define fst first
#define snd second
#define pb push_back
#define fast std::ios_base::sync_with_stdio(false);
#define LL long long
#define endl "\n"
#define lp(i,n) for(int i=0;i<(int)n;i++)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define neg(v)       memset(v,-1,sizeof(v))
#define emp(v)       memset(v,0,sizeof(v))
#define lp1(i,n)    for(int i=1;i<=(int)n;i++)
using namespace std;
#define FOR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define readfile freopen("input.txt","r",stdin);
#define writefile ("output.txt","w",stdout);
#define PI 3.1415926536
typedef pair<LL,LL> pLL;
typedef pair<int,int> ii;
LL gcd(LL a, LL b) { if(b==0) return a;   return gcd(b,a%b);  }
LL lcm (LL a, LL b) {   return a*(b/(gcd(a,b)));  }
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
inline LL toLL(string s){LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
using namespace std;
typedef vector<int> vi;
vector<int> v;
map<int,int> myP;

long long elmod(long long am, long long n)
{
	if(am >= 0) return am % n;
	else while (am < 0) am += n;
	return am;
}
int main()
{
	fast

	bool f = 0;
	int n,q;
	cin >> n >> q;

	long long odd = 0;
	long long even = 0;
	int t;
	long long am;

	while(q--)
	{
		cin >> t;

		if(t == 1)
		{
			cin >> am;
			odd += am;
			even += am;
		}
		else
		{

			if(even % 2 == 0) even--;
			else even++;
			if(odd % 2 == 0) --odd;
			else ++odd;
		}
	}

	v.resize(n+1);
	for(int i = 0 ; i < n; i++)
	{
		long long kolo = i;
		if(i%2 == 1) kolo += even;
		else kolo += odd;
		v[elmod(kolo,n)] = i ;
	}

	for(int i = 0 ; i < n ; i++) cout << v[i] + 1 << " ";

}


#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <stack>
#include <queue>
#include <vector>
#include <unordered_map>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#define fst first
#define snd second
#define pb push_back
#define fast std::ios_base::sync_with_stdio(false);
#define LL long long
#define endl "\n"
#define lp(i,n) for(int i=0;i<(int)n;i++)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define neg(v)       memset(v,-1,sizeof(v))
#define emp(v)       memset(v,0,sizeof(v))
#define lp1(i,n)    for(int i=1;i<=(int)n;i++)
using namespace std;
#define FOR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define readfile freopen("input.txt","r",stdin);
#define writefile ("output.txt","w",stdout);
#define PI 3.1415926536
typedef pair<LL,LL> pLL;
typedef pair<int,int> ii;
LL gcd(LL a, LL b) { if(b==0) return a;   return gcd(b,a%b);  }
LL lcm (LL a, LL b) {   return a*(b/(gcd(a,b)));  }
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
inline LL toLL(string s){LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
using namespace std;
typedef vector<int> vi;
int main()
{

	int n,q;
    scanf("%d%d",&n,&q);

	long long odd = 1;
	long long even = 0;
	int t;
	int am;

	while(q--)
	{
		cin >> t;

		if(t == 1)
		{
			scanf("%d",&am);
			odd += am;
			even += am;
		}
		else
		{

			if((even & 1) == 0) even--;
			else even++;
			if((odd & 1) == 0) --odd;
			else ++odd;
		}
		even += n;
		odd += n;
		even %=n;
		odd %=n;
	}
--odd;
odd += n;
odd %=n;
    int v[n+5];
	for(int i = 0 ; i < n; i++)
	{
		long long kolo = i ;
		if(((i & 1) == 1)) kolo += even;
		else kolo += odd;
		v[(int)((kolo+n)%n)%n] = i + 1 ;
	}

	for(int i = 0 ; i < n ; i++) printf("%d ",v[i]);

}


#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <stack>
#include <queue>
#include <vector>
#include <unordered_map>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#define fst first
#define snd second
#define pb push_back
#define fast std::ios_base::sync_with_stdio(false);
#define LL long long
#define endl "\n"
#define lp(i,n) for(int i=0;i<(int)n;i++)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define neg(v)       memset(v,-1,sizeof(v))
#define emp(v)       memset(v,0,sizeof(v))
#define lp1(i,n)    for(int i=1;i<=(int)n;i++)
using namespace std;
#define FOR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define readfile freopen("input.txt","r",stdin);
#define writefile ("output.txt","w",stdout);
#define PI 3.1415926536
typedef pair<LL,LL> pLL;
typedef pair<int,int> ii;
LL gcd(LL a, LL b) { if(b==0) return a;   return gcd(b,a%b);  }
LL lcm (LL a, LL b) {   return a*(b/(gcd(a,b)));  }
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
inline LL toLL(string s){LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
using namespace std;
map<int,int> v;

inline long long elmod(long long am, long long n)
{
	if(am >= 0) return am % n;
	return ((am+n)%n+n)%n;

}
int main()
{
	fast

	int n,q;
	scanf("%d%d",&n,&q);

	long long odd = 1;
	long long even = 0;
	int t;
	long long am;

	while(q--)
	{
		cin >> t;

		if(t == 1)
		{
			cin >> am;
			odd += am;
			even += am;
		}
		else
		{

			if((even & 1) == 0) even--;
			else even++;
			if((odd & 1) == 0) --odd;
			else ++odd;
		}
		even += n;
		odd += n;
		even %=n;
		odd %=n;
	}
	--odd;
	odd += n;
	odd %=n;

	for(int i = 0 ; i < n; i++)
	{
		long long kolo = i ;
		if(((i & 1) == 1)) kolo += even;
		else kolo += odd;
		v[elmod(kolo,n)] = i + 1 ;
	}

	for(int i = 0 ; i < n ; i++) printf("%d ",v[i]);

}


#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <stack>
#include <queue>
#include <vector>
#include <unordered_map>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#define fst first
#define snd second
#define pb push_back
#define fast std::ios_base::sync_with_stdio(false);
#define LL long long
#define endl "\n"
#define lp(i,n) for(int i=0;i<(int)n;i++)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define neg(v)       memset(v,-1,sizeof(v))
#define emp(v)       memset(v,0,sizeof(v))
#define lp1(i,n)    for(int i=1;i<=(int)n;i++)
using namespace std;
#define FOR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define readfile freopen("input.txt","r",stdin);
#define writefile ("output.txt","w",stdout);
#define PI 3.1415926536
typedef pair<LL,LL> pLL;
typedef pair<int,int> ii;
LL gcd(LL a, LL b) { if(b==0) return a;   return gcd(b,a%b);  }
LL lcm (LL a, LL b) {   return a*(b/(gcd(a,b)));  }
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
inline LL toLL(string s){LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
using namespace std;
map<int,int> v;

long long elmod(long long am, long long n)
{
	if(am >= 0) return am % n;
	return ((am+n)%n+n)%n;

}
int main()
{
	fast

	int n,q;
	scanf("%d%d",&n,&q);

	long long odd = 1;
	long long even = 0;
	int t;
	long long am;

	while(q--)
	{
		cin >> t;

		if(t == 1)
		{
			cin >> am;
			odd += am;
			even += am;
		}
		else
		{

			if(even % 2 == 0) even--;
			else even++;
			if(odd % 2 == 0) --odd;
			else ++odd;
		}
		even += n;
		odd += n;
		even %=n;
		odd %=n;
	}
--odd;
odd += n;
odd %=n;

	for(int i = 0 ; i < n; i++)
	{
		long long kolo = i ;
		if((i % 2 == 1)) kolo += even;
		else kolo += odd;
		v[elmod(kolo,n)] = i + 1 ;
	}

	for(int i = 0 ; i < n ; i++) printf("%d ",v[i]);

}


#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <stack>
#include <queue>
#include <vector>
#include <unordered_map>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#define fst first
#define snd second
#define pb push_back
#define fast std::ios_base::sync_with_stdio(false);
#define LL long long
#define endl "\n"
#define lp(i,n) for(int i=0;i<(int)n;i++)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define neg(v)       memset(v,-1,sizeof(v))
#define emp(v)       memset(v,0,sizeof(v))
#define lp1(i,n)    for(int i=1;i<=(int)n;i++)
using namespace std;
#define FOR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define readfile freopen("input.txt","r",stdin);
#define writefile ("output.txt","w",stdout);
#define PI 3.1415926536
typedef pair<LL,LL> pLL;
typedef pair<int,int> ii;
LL gcd(LL a, LL b) { if(b==0) return a;   return gcd(b,a%b);  }
LL lcm (LL a, LL b) {   return a*(b/(gcd(a,b)));  }
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
inline LL toLL(string s){LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
using namespace std;
typedef vector<int> vi;
vector<int> v;
map<int,int> myP;

long long elmod(long long am, long long n)
{
	if(am >= 0) return am % n;
	else ((am+n)%n+n)%n;
	return am;
}
int main()
{
	fast

	int n,q;
	cin >> n >> q;

	long long odd = 1;
	long long even = 0;
	int t;
	long long am;

	while(q--)
	{
		cin >> t;

		if(t == 1)
		{
			cin >> am;
			odd += am;
			even += am;
		}
		else
		{

			if(even % 2 == 0) even--;
			else even++;
			if(odd % 2 == 0) --odd;
			else ++odd;
		}
		even += n;
		odd += n;
		even %=n;
		odd %=n;
	}
--odd;
odd += n;
odd %=n;
	v.resize(n+1);
	for(int i = 0 ; i < n; i++)
	{
		long long kolo = i ;
		if((i % 2 == 1)) kolo += even;
		else kolo += odd;
		v[elmod(kolo,n)] = i + 1 ;
	}

	for(int i = 0 ; i < n ; i++) cout << v[i]<< " ";

}


#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <stack>
#include <queue>
#include <vector>
#include <unordered_map>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#define fst first
#define snd second
#define pb push_back
#define fast std::ios_base::sync_with_stdio(false);
#define LL long long
#define endl "\n"
#define lp(i,n) for(int i=0;i<(int)n;i++)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define neg(v)       memset(v,-1,sizeof(v))
#define emp(v)       memset(v,0,sizeof(v))
#define lp1(i,n)    for(int i=1;i<=(int)n;i++)
using namespace std;
#define FOR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define readfile freopen("input.txt","r",stdin);
#define writefile ("output.txt","w",stdout);
#define PI 3.1415926536
typedef pair<LL,LL> pLL;
typedef pair<int,int> ii;
LL gcd(LL a, LL b) { if(b==0) return a;   return gcd(b,a%b);  }
LL lcm (LL a, LL b) {   return a*(b/(gcd(a,b)));  }
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
inline LL toLL(string s){LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
using namespace std;
typedef vector<int> vi;
int main()
{

	int n,q;
    scanf("%d%d",&n,&q);

	long long odd = 1;
	long long even = 0;
	int t;
	int am;

	while(q--)
	{
		scanf("%d",&t);

		if(t == 1)
		{
			scanf("%d",&am);
			odd += am;
			even += am;
		}
		else
		{

			if((even & 1) == 0) even--;
			else even++;
			if((odd & 1) == 0) --odd;
			else ++odd;
		}
		even += n;
		odd += n;
		even %=n;
		odd %=n;
	}
--odd;
odd += n;
odd %=n;
    int v[n+5];
	for(int i = 0 ; i < n; i++)
	{
		long long kolo = i ;
		if(((i & 1) == 1)) kolo += even;
		else kolo += odd;
		v[(int)((kolo+n)%n)%n] = i + 1 ;
	}

	for(int i = 0 ; i < n ; i++) printf("%d ",v[i]);

}


#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <stack>
#include <queue>
#include <vector>
#include <unordered_map>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#define fst first
#define snd second
#define pb push_back
#define fast std::ios_base::sync_with_stdio(false);
#define LL long long
#define endl "\n"
#define lp(i,n) for(int i=0;i<(int)n;i++)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define neg(v)       memset(v,-1,sizeof(v))
#define emp(v)       memset(v,0,sizeof(v))
#define lp1(i,n)    for(int i=1;i<=(int)n;i++)
using namespace std;
#define FOR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define readfile freopen("input.txt","r",stdin);
#define writefile ("output.txt","w",stdout);
#define PI 3.1415926536
typedef pair<LL,LL> pLL;
typedef pair<int,int> ii;
LL gcd(LL a, LL b) { if(b==0) return a;   return gcd(b,a%b);  }
LL lcm (LL a, LL b) {   return a*(b/(gcd(a,b)));  }
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
inline LL toLL(string s){LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
using namespace std;
typedef vector<int> vi;
vector<int> v;
map<int,int> myP;

long long elmod(long long am, long long n)
{
	if(am >= 0) return am % n;
	else while (am < 0) am += n;
	return am;
}
int main()
{
	fast

	int n,q;
	cin >> n >> q;

	long long odd = 1;
	long long even = 0;
	int t;
	long long am;

	while(q--)
	{
		cin >> t;

		if(t == 1)
		{
			cin >> am;
			odd += am;
			even += am;
		}
		else
		{

			if(even % 2 == 0) even--;
			else even++;
			if(odd % 2 == 0) --odd;
			else ++odd;
		}
		even += n;
		odd += n;
		even %=n;
		odd %=n;
	}
--odd;
odd += n;
odd %=n;
	v.resize(n+1);
	for(int i = 0 ; i < n; i++)
	{
		long long kolo = i ;
		if((i % 2 == 1)) kolo += even;
		else kolo += odd;
		v[elmod(kolo,n)] = i + 1 ;
	}

	for(int i = 0 ; i < n ; i++) cout << v[i]<< " ";

}


#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <stack>
#include <queue>
#include <vector>
#include <unordered_map>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#define fst first
#define snd second
#define pb push_back
#define fast std::ios_base::sync_with_stdio(false);
#define LL long long
#define endl "\n"
#define lp(i,n) for(int i=0;i<(int)n;i++)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define neg(v)       memset(v,-1,sizeof(v))
#define emp(v)       memset(v,0,sizeof(v))
#define lp1(i,n)    for(int i=1;i<=(int)n;i++)
using namespace std;
#define FOR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define readfile freopen("input.txt","r",stdin);
#define writefile ("output.txt","w",stdout);
#define PI 3.1415926536
typedef pair<LL,LL> pLL;
typedef pair<int,int> ii;
LL gcd(LL a, LL b) { if(b==0) return a;   return gcd(b,a%b);  }
LL lcm (LL a, LL b) {   return a*(b/(gcd(a,b)));  }
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
inline LL toLL(string s){LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
using namespace std;
typedef vector<int> vi;
vector<int> v;
map<int,int> myP;
int main()
{
	fast

	bool f = 0;
	int n,q;
	cin >> n >> q;
	long long shift = 0;
	int t;
	long long am;
	while(q--)
	{
		cin >> t;

		if(t == 1)
		{
			cin >> am;
			if(am >= 0) shift += am;
			else shift += (n) + -1LL*am;
		}
		else f = !f;
	}
	shift %= n;
	v.resize(n);
	for(int i = 0 ; i < n; i++)
	{
		v[(i+shift)%n] = i;
		myP[i] = (i+shift)%n;
	}
	if(f)
	{
		for(int i = 1 ; i < n ; i += 2)
		{
			v[myP[i]] = i - 1;
			v[myP[i-1]] = i;
		}
	}

	rep(k,v) cout << v[k]+1 << " ";

}


#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <stack>
#include <queue>
#include <vector>
#include <unordered_map>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#define fst first
#define snd second
#define pb push_back
#define fast std::ios_base::sync_with_stdio(false);
#define LL long long
#define endl "\n"
#define lp(i,n) for(int i=0;i<(int)n;i++)
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);i++)
#define neg(v)       memset(v,-1,sizeof(v))
#define emp(v)       memset(v,0,sizeof(v))
#define lp1(i,n)    for(int i=1;i<=(int)n;i++)
using namespace std;
#define FOR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define readfile freopen("input.txt","r",stdin);
#define writefile ("output.txt","w",stdout);
#define PI 3.1415926536
typedef pair<LL,LL> pLL;
typedef pair<int,int> ii;
LL gcd(LL a, LL b) { if(b==0) return a;   return gcd(b,a%b);  }
LL lcm (LL a, LL b) {   return a*(b/(gcd(a,b)));  }
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
inline LL toLL(string s){LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
using namespace std;
map<int,int> v;

long long elmod(long long am, long long n)
{
	if(am >= 0) return am % n;
	return ((am+n)%n+n)%n;

}
int main()
{

	int n,q;
	scanf("%d%d",&n,&q);

	long long odd = 1;
	long long even = 0;
	int t;
	long long am;

	while(q--)
	{
		scanf("%d",&t);

		if(t == 1)
		{
			scanf("%d",&am);
			odd += am;
			even += am;
		}
		else
		{

			if(even % 2 == 0) even--;
			else even++;
			if(odd % 2 == 0) --odd;
			else ++odd;
		}
		even += n;
		odd += n;
		even %=n;
		odd %=n;
	}
--odd;
odd += n;
odd %=n;

	for(int i = 0 ; i < n; i++)
	{
		long long kolo = i ;
		if((i % 2 == 1)) kolo += even;
		else kolo += odd;
		v[elmod(kolo,n)] = i + 1 ;
	}

	for(int i = 0 ; i < n ; i++) printf("%d ",v[i]);

}