#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vvi            vector<vi>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(c,i)        for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)    (find(all(c),x) != (c).end())
using namespace std;
ll mod=1e9+7;
#define N  100005
ll  n,m;
vector<pii> ans(N);
vector<pair<pii,ll>> edg;
vvi adj(N);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
    //cin>>TESTS;
    //ll cs=1;
    while(TESTS--)
    {
        cin >> n >> m;
        priority_queue<pii,vector<pii>,greater<pii> > pq;
        rep(i,0,m){
            ll w,b;
            cin >> w >> b;
            edg.pb(mp(mp(w,(1-b)),i));
        }
        rep(i,1,n+1){
            pq.push(mp(i+2,i));
        }
        sort(all(edg));
        //for(auto &&it:edg) cout << it.F << " " << it.S << "\n";

        ll fl=0,curr=1;
        rep(i,0,m){
            if(edg[i].F.S==0){
                ans[edg[i].S]=mp(curr,curr+1);
                curr++;
            }
            else{
                pii sel=pq.top(); pq.pop();
                //cout << sel.F << " " << sel.S << "\n";
                if(sel.F>curr){fl=1; break;}
                ans[edg[i].S]=mp(sel.S,sel.F);
                // ans.pb(mp(sel.S,sel.F));
                pq.push(mp(sel.F+1,sel.S));
            }
        }
        if(fl==1) cout << -1 << "\n";
        else{
            rep(i,0,m){
                cout << ans[i].F << " " << ans[i].S << "\n";
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ld double
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define vvi vector<vi >
#define str string
#define vs vector<str>
#define vb vector<bool>
#define slli set<lli>
#define mii map<int, int>
#define mlli map<int, lli>
#define msi map<str, int>
#define mp make_pair
#define pii pair<int, int>
#define pll pair<lli, lli>
#define vpii vector<pii >
#define vpll vector<pll >
#define pb push_back
#define loop(i, s, l, j) for(int i = s; i < l; i += j)
#define rloop(i, s, l, j) for(int i = s; i >= l; i -= j)
#define rep(i, n) loop(i,0,n,1)
#define rrep(i, n) rloop(i,n-1,0,1)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ft first
#define sd second
#define mit mii::iterator
#define vit vi::iterator
#define all(a) a.begin(),a.end()
#define min3(a, b, c) min(a, min(b, c))
#define mod 1000000007
#define inf 100000000000000000
#define limit 200005
/**********************************************************************************************************************************************/
int dx4[4] = {0, -1, 0, 1};
int dy4[4] = {1, 0, -1, 0};
int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Power(int base,lli exp){int ans=1;  while(exp > 0){if(exp&1)ans=(1LL*ans*base)%mod; exp=exp>>1; base=(1LL*base*base)%mod;}  return ans;}
/**********************************************************************************************************************************************/
bool comp(pair<int, pii > &o1, pair<int, pii > &o2)
{
    return ((o1.ft < o2.ft) || (o1.ft == o2.ft && o1.sd.ft > o2.sd.ft));
}
void input()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, pii > > a(m);
    rep(i,m)
    {
        cin >> a[i].ft >> a[i].sd.ft;
        a[i].sd.sd = i;
    }

    sort(all(a), comp);
    lli c = 0;
    int z = 0;
    int o = 0;

    rep(i,m)
    {
        if(a[i].sd.ft == 0)
        {
            z++;
            if(z > c)
            {
                cout << -1 << '\n';
                return;
            }
        }
        else
        {
            o++;
            c = 1LL*o*(o-1)/2;
        }
    }

    vpii e;
    rep(i,n-1)
        e.pb(mp(1,i+2));

    vpii e_;
    loop(j,3,n+1,1)
    {
        loop(i,2,j,1)
            e_.pb(mp(i,j));
        if(e_.size() > 100001)
            break;
    }

    int p1 = 0, p2 = 0;
    vpii ans(m);
    rep(i,m)
    {
        int j = a[i].sd.sd;
        if(a[i].sd.ft == 0)
        {
            ans[j] = e_[p2];
            p2++;
        }
        else
        {
            ans[j] = e[p1];
            p1++;
        }
    }
    rep(i,m)
        cout << ans[i].ft << ' ' << ans[i].sd << '\n';
}

int main()
{
    fastio();
    int q = 1;
    //cin >> q;
    while(q--)
        input();
}


#include<bits/stdc++.h>
using namespace std;
#define ld double
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define vvi vector<vi >
#define str string
#define vs vector<str>
#define vb vector<bool>
#define slli set<lli>
#define mii map<int, int>
#define mlli map<int, lli>
#define msi map<str, int>
#define mp make_pair
#define pii pair<int, int>
#define pll pair<lli, lli>
#define vpii vector<pii >
#define vpll vector<pll >
#define pb push_back
#define loop(i, s, l, j) for(int i = s; i < l; i += j)
#define rloop(i, s, l, j) for(int i = s; i >= l; i -= j)
#define rep(i, n) loop(i,0,n,1)
#define rrep(i, n) rloop(i,n-1,0,1)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ft first
#define sd second
#define mit mii::iterator
#define vit vi::iterator
#define all(a) a.begin(),a.end()
#define min3(a, b, c) min(a, min(b, c))
#define mod 1000000007
#define inf 100000000000000000
#define limit 200005
/**********************************************************************************************************************************************/
int dx4[4] = {0, -1, 0, 1};
int dy4[4] = {1, 0, -1, 0};
int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Power(int base,lli exp){int ans=1;  while(exp > 0){if(exp&1)ans=(1LL*ans*base)%mod; exp=exp>>1; base=(1LL*base*base)%mod;}  return ans;}
/**********************************************************************************************************************************************/

void input()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, pii > > a(m);
    rep(i,m)
    {
        cin >> a[i].ft >> a[i].sd.ft;
        a[i].sd.sd = i;
    }

    sort(all(a));
    lli c = 0;
    int z = 0;
    int o = 0;

    rep(i,m)
    {
        if(a[i].sd.ft == 0)
        {
            z++;
            if(z > c)
            {
                cout << -1 << '\n';
                return;
            }
        }
        else
        {
            o++;
            c = 1LL*o*(o-1)/2;
        }
    }

    vpii e;
    rep(i,n-1)
        e.pb(mp(1,i+2));

    vpii e_;
    loop(j,3,n+1,1)
    {
        loop(i,2,j,1)
            e_.pb(mp(i,j));
        if(e_.size() > 100001)
            break;
    }

    int p1 = 0, p2 = 0;
    vpii ans(m);
    rep(i,m)
    {
        int j = a[i].sd.sd;
        if(a[i].sd.ft == 0)
        {
            ans[j] = e_[p2];
            p2++;
        }
        else
        {
            ans[j] = e[p1];
            p1++;
        }
    }
    rep(i,m)
        cout << ans[i].ft << ' ' << ans[i].sd << '\n';
}

int main()
{
    fastio();
    int q = 1;
    //cin >> q;
    while(q--)
        input();
}


#include<bits/stdc++.h>
using namespace std;
#define ld double
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define vvi vector<vi >
#define str string
#define vs vector<str>
#define vb vector<bool>
#define slli set<lli>
#define mii map<int, int>
#define mlli map<int, lli>
#define msi map<str, int>
#define mp make_pair
#define pii pair<int, int>
#define pll pair<lli, lli>
#define vpii vector<pii >
#define vpll vector<pll >
#define pb push_back
#define loop(i, s, l, j) for(int i = s; i < l; i += j)
#define rloop(i, s, l, j) for(int i = s; i >= l; i -= j)
#define rep(i, n) loop(i,0,n,1)
#define rrep(i, n) rloop(i,n-1,0,1)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ft first
#define sd second
#define mit mii::iterator
#define vit vi::iterator
#define all(a) a.begin(),a.end()
#define min3(a, b, c) min(a, min(b, c))
#define mod 1000000007
#define inf 100000000000000000
#define limit 200005
/**********************************************************************************************************************************************/
int dx4[4] = {0, -1, 0, 1};
int dy4[4] = {1, 0, -1, 0};
int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Power(int base,lli exp){int ans=1;  while(exp > 0){if(exp&1)ans=(1LL*ans*base)%mod; exp=exp>>1; base=(1LL*base*base)%mod;}  return ans;}
/**********************************************************************************************************************************************/

void input()
{
    int n, m;
    cin >> n >> m;
    vpii a(m);
    rep(i,m)
        cin >> a[i].ft >> a[i].sd;

    sort(all(a));
    lli c = 0;
    int z = 0;
    int o = 0;

    rep(i,m)
    {
        if(a[i].sd == 0)
        {
            z++;
            if(z > c)
            {
                cout << -1 << '\n';
                return;
            }
        }
        else
        {
            o++;
            c = 1LL*o*(o-1)/2;
        }
    }

    vpii e;
    rep(i,n-1)
        e.pb(mp(1,i+2));

    vpii e_;
    loop(j,3,n+1,1)
    {
        loop(i,2,j,1)
            e_.pb(mp(i,j));
        if(e_.size() > 100001)
            break;
    }

    int p1 = 0, p2 = 0;
    rep(i,m)
    {
        if(a[i].sd == 0)
        {
            cout << e_[p2].ft << ' ' << e_[p2].sd << '\n';
            p2++;
        }
        else
        {
            cout << e[p1].ft << ' ' << e[p1].sd << '\n';
            p1++;
        }
    }
}

int main()
{
    fastio();
    int q = 1;
    //cin >> q;
    while(q--)
        input();
}


#include <bits/stdc++.h>
using namespace std;
int n, m, k;
struct edge
{
    int we, is, nr;
} v[100001];
struct graph
{
    int a, b;
} G[100001];
bool cmp(edge a, edge b)
{
    if(a.we!=b.we)
        return a.we<b.we;
    return a.is>b.is;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    for(int i=1; i<=m; i++)
    {
        cin>>v[i].we>>v[i].is;
        v[i].nr=i;
    }
    sort(v+1, v+m+1, cmp);
    int d=3, e=1, c=2;
    for(int i=1; i<=m; i++)
    {
        int x=v[i].nr;
        if(!v[i].is)
        {
            if(d>e)
            {
                cout<<-1;
                return 0;
            }
            G[x].a=c;
            G[x].b=d;
            c++;
            if(c==d)
            {
                c=2;
                d++;
            }
        }
        else
        {
            G[x].a=1;
            e++;
            G[x].b=e;
        }
    }
    for(int i=1; i<=m; i++)
        cout<<G[i].a<<' '<<G[i].b<<'\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, m;
struct edge
{
    int we, is, nr;
} v[100001];
struct graph
{
    int a, b;
} G[100001];
bool cmp(edge a, edge b)
{
    if(a.we!=b.we)
        return a.we<b.we;
    return a.is>b.is;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    for(int i=1; i<=m; i++)
    {
        cin>>v[i].we>>v[i].is;
        v[i].nr=i;
    }
    sort(v+1, v+m+1, cmp);
    int d=3, e=1, c=2;
    for(int i=1; i<=m; i++)
    {
        int x=v[i].nr;
        if(!v[i].is)
        {
            if(d>e)
            {
                cout<<-1;
                return 0;
            }
            G[x].a=c;
            G[x].b=d;
            c++;
            if(c==d)
            {
                c=2;
                d++;
            }
        }
        else
        {
            G[x].a=1;
            e++;
            G[x].b=e;
        }
    }
    for(int i=1; i<=m; i++)
        cout<<G[i].a<<' '<<G[i].b<<'\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, m;
struct weigh
{
    int we, is, nr;
} v[100001];
struct graph
{
    int a, b;
} G[100001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    for(int i=1; i<=m; i++)
    {
        cin>>v[i].we>>v[i].is;
        v[i].nr=i;
    }
    int d=2, e=1, c=2;
    for(int i=1; i<=m; i++)
    {
        int x=v[i].nr;
        if(!v[i].is)
        {
            if(d>e)
            {
                cout<<-1;
                return 0;
            }
            G[x].a=c;
            G[x].b=d;
            c++;
            if(c==d)
            {
                c=2;
                d++;
            }
        }
        else
        {
            G[x].a=1;
            e++;
            G[x].b=e;
        }
    }
    for(int i=1; i<=m; i++)
        cout<<G[i].a<<' '<<G[i].b<<'\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, m;
struct weigh
{
    int we, is, nr;
} v[100001];
struct graph
{
    int a, b;
} G[100001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    for(int i=1; i<=m; i++)
    {
        cin>>v[i].we>>v[i].is;
        v[i].nr=i;
    }
    int d=3, e=1, c=2;
    for(int i=1; i<=m; i++)
    {
        int x=v[i].nr;
        if(!v[i].is)
        {
            if(d>e)
            {
                cout<<-1;
                return 0;
            }
            G[x].a=c;
            G[x].b=d;
            c++;
            if(c==d)
            {
                c=2;
                d++;
            }
        }
        else
        {
            G[x].a=1;
            e++;
            G[x].b=e;
        }
    }
    for(int i=1; i<=m; i++)
        cout<<G[i].a<<' '<<G[i].b<<'\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, m;
struct weigh
{
    int we, is, nr;
} v[100001];
struct graph
{
    int a, b;
} G[100001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    for(int i=1; i<=m; i++)
    {
        cin>>v[i].we>>v[i].is;
        v[i].nr=i;
    }
    int d=1, e=1, c=2;
    for(int i=1; i<=m; i++)
    {
        int x=v[i].nr;
        if(!v[i].is)
        {
            if(d>e)
            {
                cout<<-1;
                return 0;
            }
            G[x].a=c;
            G[x].b=d;
            c++;
            if(c==d)
            {
                c=2;
                d++;
            }
        }
        else
        {
            G[x].a=1;
            e++;
            G[x].b=e;
        }
    }
    for(int i=1; i<=m; i++)
        cout<<G[i].a<<' '<<G[i].b<<'\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, m;
struct edge
{
    int we, is, nr;
} v[100001];
struct graph
{
    int a, b;
} G[100001];
bool cmp(edge a, edge b)
{
    if(a.we!=b.we)
        return a.we<=b.we;
    return a.is>=b.is;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    for(int i=1; i<=m; i++)
    {
        cin>>v[i].we>>v[i].is;
        v[i].nr=i;
    }
    sort(v+1, v+m+1, cmp);
    int d=3, e=1, c=2;
    for(int i=1; i<=m; i++)
    {
        int x=v[i].nr;
        if(!v[i].is)
        {
            if(d>e)
            {
                cout<<-1;
                return 0;
            }
            G[x].a=c;
            G[x].b=d;
            c++;
            if(c==d)
            {
                c=2;
                d++;
            }
        }
        else
        {
            G[x].a=1;
            e++;
            G[x].b=e;
        }
    }
    for(int i=1; i<=m; i++)
        cout<<G[i].a<<' '<<G[i].b<<'\n';
    return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second

using namespace std;

const double pi=acos(-1);
const int N=2e5+7,mod=1000000007,M=2e9;

int n,m,u,v;

//scanf("%d",&);
struct edge{
    int w,id;
    bool st;

    operator<(const edge& a)const{
        if(a.w==w)
            return a.st;
        return a.w<w;
    }
}a[N],t;

priority_queue<edge> q;
pii ans[N];
stack<pii> tmp;

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d%d",&u,&v);
        a[i]={u,i,v};
        q.push(a[i]);
    }
    v=2;

    while(!q.empty()){
        t=q.top();
        q.pop();
        if(t.st){
            ans[t.id]={v-1,v};
            u=v-2;
            while(u&&tmp.size()<m)
                tmp.push({u--,v});
            v++;
        }
        else{
            if(tmp.empty())
                return puts("-1");
            else{
                ans[t.id]=tmp.top();
                tmp.pop();
            }
        }
    }
    for(int i=0;i<m;i++){
        printf("%d %d\n",ans[i].ff,ans[i].ss);
    }
    return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second

using namespace std;

const double pi=acos(-1);
const int N=2e5+7,mod=1000000007,M=2e9;

int n,m,u,v;

//scanf("%d",&);
struct edge{
    int w,id;
    bool st;

    operator<(const edge& a)const{
        return a.w<w;
    }
}a[N],t;

priority_queue<edge> q;
pii ans[N];
stack<pii> tmp;

struct dsu{
    int p[N],sz[N];

    void init(){
        fill(sz,sz+n+1,1);
        iota(p,p+n+1,0);
    }

    int par(int x){
        return p[x]=(x==p[x]?x:par(p[x]));
    }

    bool con(int x,int y){
        x=par(x);
        y=par(y);
        if(x==y)
            return 0;
        if(sz[y]>sz[x])
            swap(x,y);
        p[y]=x;
        sz[x]+=sz[y];
        return 1;
    }
};

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d%d",&u,&v);
        a[i]={u,i,v};
        q.push(a[i]);
    }
    v=2;

    while(!q.empty()){
        t=q.top();
        q.pop();
        if(t.st){
            ans[t.id]={v-1,v};
            u=v-2;
            while(u&&tmp.size()<m)
                tmp.push({u--,v});
            v++;
        }
        else{
            if(tmp.empty())
                return puts("-1");
            else{
                ans[t.id]=tmp.top();
                tmp.pop();
            }
        }
    }
    for(int i=0;i<m;i++){
        printf("%d %d\n",ans[i].ff,ans[i].ss);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/

double eps = .000000001;
bool cmp(const pair<pair<int, int>, int> &a, const pair<pair<int, int>, int> &b){
    if (a.first.first != b.first.first){
        return a.first.first < b.first.first;
    }else{
        return a.first.second > b.first.second;
    }
}
int main(){
  prep();
  int n, m;
  cin >> n >> m;

  vector<pair<pair<int, int>, int> > edges;

  for (int i=0; i<m; i++){
      int a, b;
      cin >> a >> b;
      edges.emplace_back(make_pair(a, b), i);
  }
  sort(edges.begin(), edges.end(), cmp);

  pair<int, int> res[m+1];
  int curnode = 1;
  int curconnect = 1;
  int curlast = 3;

  for (int i=0; i<edges.size(); i++){
      int a = edges[i].first.first;
      int b = edges[i].first.second;
      int ind = edges[i].second;
      if (b == 0){
          if (curconnect > curnode || curlast > curnode){
              cout << -1;
              return 0;
          }
          res[ind] = {curconnect, curlast};
          curconnect++;
          if (curlast-curconnect <= 1){
              curlast++;
              curconnect = 1;
          }

      }else{
          curnode++;
          res[ind] = {curnode, curnode-1};
      }
  }

  for (int i=0; i<m; i++){
      cout << res[i].first << " " << res[i].second << '\n';
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/

double eps = .000000001;

int main ()
{
  prep();
  int n, m;
  cin >> n >> m;

  vector<pair<pair<int, int>, int> > edges;
  for (int i=0; i<m; i++){
      int a, b;
      cin >> a >> b;
      edges.emplace_back(make_pair(a, b), i);
  }
  sort(edges.begin(), edges.end());
  if (edges[0].first.second == 0){
      cout << -1;
      return 0;
  }
  pair<int, int> res[m+1];
  int curnode = 1;
  for (int i=0; i<edges.size(); i++){
      int a = edges[i].first.first;
      int b = edges[i].first.second;
      int ind = edges[i].second;
      if (b == 0){
          res[ind] = {2, 1};
      }else{
          curnode++;
          res[ind] = {curnode, curnode-1};
      }
  }
  if (curnode != n){
      cout << -1;
      return 0;
  }
  for (int i=0; i<m; i++){
      cout << res[i].first << " " << res[i].second << '\n';
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/

double eps = .000000001;

int main ()
{
  prep();
  int n, m;
  cin >> n >> m;

  vector<pair<pair<int, int>, int> > edges;
  for (int i=0; i<m; i++){
      int a, b;
      cin >> a >> b;
      edges.emplace_back(make_pair(a, b), i);
  }
  sort(edges.begin(), edges.end());
  if (edges[0].first.second == 0){
      cout << -1;
      return 0;
  }
  pair<int, int> res[m+1];
  int curnode = 1;
  int curconnect = 1;
  int curlast = 3;

  for (int i=0; i<edges.size(); i++){
      int a = edges[i].first.first;
      int b = edges[i].first.second;
      int ind = edges[i].second;
      if (b == 0){
          if (curconnect > curnode || curlast > curnode){
              cout << -1;
              return 0;
          }
          res[ind] = {curconnect, curlast};
          curconnect++;
          if (curlast-curconnect <= 1){
              curlast++;
              curconnect = 1;
          }

      }else{
          curnode++;
          res[ind] = {curnode, curnode-1};
      }
  }
  if (curnode != n){
      cout << -1;
      return 0;
  }
  for (int i=0; i<m; i++){
      cout << res[i].first << " " << res[i].second << '\n';
  }
  return 0;
}


/***
 ** " Love the life you live. Live the life you love. "
 **     -- Bob Marley
***/

/**
  *  Author: dhruv_gheewala
  *  Problem: Lazy Student
  *  Date:   16.04.2020
  *  Time:   23:44:27
**/

#if __has_include("debug.h")
    #include "debug.h"
#else
    #include<bits/stdc++.h>
    using namespace std;

    #define p(str) 7
    #define o(str) 42
    #define fundri 108
    #define d(...) 1729
#endif

#define int long long
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

const bool testcases = 0;
#define ff first
#define ss second
#define endl '\n'
#define all(s) s.begin(),s.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define test int T = 1;if(testcases)cin >> T;for(int tc = 1 ; tc <= T ; tc++)
#define make_unique(vec) sort(all(vec));vec.erase(unique(all(vec)),vec.end())
#define sort_by(cont,expr) sort(all(cont),[&](const auto &lhs,const auto &rhs){return expr;})

ll seed;mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l=0,int r=INT_MAX){return uniform_int_distribution<int>(l,r)(rng);}

template<typename T>bool isPrime(T n){for(T i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}
template<typename T>inline bool in_range(T a,T l,T r){return (a>=l&&a<=r);}

template<typename T,typename U>inline istream& operator >>(istream& in,pair<T,U> &a)
{in>>a.ff>>a.ss;return in;}
template<typename T>inline istream& operator >>(istream& in,vector<T> &a)
{for(auto &x : a)in>>x;return in;}
template<typename TAIL>inline void inp(TAIL& T){cin>>T;}
template<typename HEAD,typename... TAIL>inline void inp(HEAD &H,TAIL&... T){cin>>H;inp(T...);}

int32_t main(int32_t argc, char **argv)
{
    std::chrono::time_point<std::chrono::high_resolution_clock> start_time, end_time;
    start_time = std::chrono::high_resolution_clock::now();

    #ifdef DHRUV_GHEEWALA
        freopen("INPUT.txt","r",stdin);
        freopen("OUTPUT.txt","w",stdout);
        freopen("DEBUG.txt","w",stderr);
    #endif

    fast;
    int n, m, w;
    bool b;

    cin >> n >> m;

    vector<pair<pii, int>> e(m);
    for(int i = 0 ; i < m ; i++)
    {
    	cin >> e[i].ff;
    	e[i].ss = i;
    }

    sort_by(e, lhs.ff == rhs.ff ? lhs.ss > rhs.ss : lhs.ff < rhs.ff);

    vector<pii> ans(m);
    int l = 2, r = 3, cur = 2;

    for(int i = 0 ; i < m ; i++)
    {
    	if(e[i].ff.ss)
    	{
    		ans[e[i].ss] = {1, cur};
    		cur++;
    		continue;
    	}
    	if(r > cur)
    	{
    		cout << -1 << endl;
    		return 0;
    	}
    	ans[e[i].ss] = {l, r};
    	if(r == n)
    	{
    		l += 1;
    		r = l + 1;
    	}
    	else
    	{
    		r += 1;
    	}
    }

    for(pii &p : ans)
    	cout << p.ff << " " << p.ss << endl;

    end_time = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
    o("\n\n");
    if(elapsed_time<10000)
        o("Elapsed Time: "<<elapsed_time<<" ms\n");
    else
        o("Elapsed Time: "<<elapsed_time/1000<<" s\n");

    return 0;
}


/***
 ** " Love the life you live. Live the life you love. "
 **     -- Bob Marley
***/

/**
  *  Author: dhruv_gheewala
  *  Problem: Lazy Student
  *  Date:   16.04.2020
  *  Time:   23:53:08
**/

#if __has_include("debug.h")
    #include "debug.h"
#else
    #include<bits/stdc++.h>
    using namespace std;

    #define p(str) 7
    #define o(str) 42
    #define fundri 108
    #define d(...) 1729
#endif

#define int long long
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

const bool testcases = 0;
#define ff first
#define ss second
#define endl '\n'
#define all(s) s.begin(),s.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define test int T = 1;if(testcases)cin >> T;for(int tc = 1 ; tc <= T ; tc++)
#define make_unique(vec) sort(all(vec));vec.erase(unique(all(vec)),vec.end())
#define sort_by(cont,expr) sort(all(cont),[&](const auto &lhs,const auto &rhs){return expr;})

ll seed;mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l=0,int r=INT_MAX){return uniform_int_distribution<int>(l,r)(rng);}

template<typename T>bool isPrime(T n){for(T i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}
template<typename T>inline bool in_range(T a,T l,T r){return (a>=l&&a<=r);}

template<typename T,typename U>inline istream& operator >>(istream& in,pair<T,U> &a)
{in>>a.ff>>a.ss;return in;}
template<typename T>inline istream& operator >>(istream& in,vector<T> &a)
{for(auto &x : a)in>>x;return in;}
template<typename TAIL>inline void inp(TAIL& T){cin>>T;}
template<typename HEAD,typename... TAIL>inline void inp(HEAD &H,TAIL&... T){cin>>H;inp(T...);}

int32_t main(int32_t argc, char **argv)
{
    std::chrono::time_point<std::chrono::high_resolution_clock> start_time, end_time;
    start_time = std::chrono::high_resolution_clock::now();

    #ifdef DHRUV_GHEEWALA
        freopen("INPUT.txt","r",stdin);
        freopen("OUTPUT.txt","w",stdout);
        freopen("DEBUG.txt","w",stderr);
    #endif

    fast;
    int n, m, w;
    bool b;

    cin >> n >> m;

    vector<pair<pii, int>> e(m);
    for(int i = 0 ; i < m ; i++)
    {
    	cin >> e[i].ff;
    	e[i].ss = i;
    }

    sort_by(e, lhs.ff.ff == rhs.ff.ff ? lhs.ff.ss > rhs.ff.ss : lhs.ff.ff < rhs.ff.ff);
    d(e);

    vector<pii> ans(m);
    int cur = 1, l = 2, r = 3;

    for(int i = 0 ; i < m ; i++)
    {
    	if(e[i].ff.ss)
    	{
    		cur++;
    		ans[e[i].ss] = {1, cur};
    		continue;
    	}
    	if(r > cur)
    	{
    		d(cur, r);
    		cout << -1 << endl;
    		return 0;
    	}
    	ans[e[i].ss] = {l, r};
    	if(r == n)
    	{
    		l += 1;
    		r = l + 1;
    	}
    	else
    	{
    		r += 1;
    	}
    }

    for(pii &p : ans)
    	cout << p.ff << " " << p.ss << endl;

    end_time = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
    o("\n\n");
    if(elapsed_time<10000)
        o("Elapsed Time: "<<elapsed_time<<" ms\n");
    else
        o("Elapsed Time: "<<elapsed_time/1000<<" s\n");

    return 0;
}


/***
 ** " Love the life you live. Live the life you love. "
 **     -- Bob Marley
***/

/**
  *  Author: dhruv_gheewala
  *  Problem: Lazy Student
  *  Date:   17.04.2020
  *  Time:   00:00:11
**/

#if __has_include("debug.h")
    #include "debug.h"
#else
    #include<bits/stdc++.h>
    using namespace std;

    #define p(str) 7
    #define o(str) 42
    #define fundri 108
    #define d(...) 1729
#endif

#define int long long
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

const bool testcases = 0;
#define ff first
#define ss second
#define endl '\n'
#define all(s) s.begin(),s.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define test int T = 1;if(testcases)cin >> T;for(int tc = 1 ; tc <= T ; tc++)
#define make_unique(vec) sort(all(vec));vec.erase(unique(all(vec)),vec.end())
#define sort_by(cont,expr) sort(all(cont),[&](const auto &lhs,const auto &rhs){return expr;})

ll seed;mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l=0,int r=INT_MAX){return uniform_int_distribution<int>(l,r)(rng);}

template<typename T>bool isPrime(T n){for(T i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}
template<typename T>inline bool in_range(T a,T l,T r){return (a>=l&&a<=r);}

template<typename T,typename U>inline istream& operator >>(istream& in,pair<T,U> &a)
{in>>a.ff>>a.ss;return in;}
template<typename T>inline istream& operator >>(istream& in,vector<T> &a)
{for(auto &x : a)in>>x;return in;}
template<typename TAIL>inline void inp(TAIL& T){cin>>T;}
template<typename HEAD,typename... TAIL>inline void inp(HEAD &H,TAIL&... T){cin>>H;inp(T...);}

int32_t main(int32_t argc, char **argv)
{
    std::chrono::time_point<std::chrono::high_resolution_clock> start_time, end_time;
    start_time = std::chrono::high_resolution_clock::now();

    #ifdef DHRUV_GHEEWALA
        freopen("INPUT.txt","r",stdin);
        freopen("OUTPUT.txt","w",stdout);
        freopen("DEBUG.txt","w",stderr);
    #endif

    fast;
    int n, m, w;
    bool b;

    cin >> n >> m;

    vector<pair<pii, int>> e(m);
    for(int i = 0 ; i < m ; i++)
    {
    	cin >> e[i].ff;
    	e[i].ss = i;
    }

    sort_by(e, lhs.ff.ff == rhs.ff.ff ? lhs.ff.ss > rhs.ff.ss : lhs.ff.ff < rhs.ff.ff);
    d(e);

    vector<pii> ans(m);
    int cur = 1, l = 2, r = 3;

    for(int i = 0 ; i < m ; i++)
    {
    	if(e[i].ff.ss)
    	{
    		cur++;
    		ans[e[i].ss] = {1, cur};
    		continue;
    	}
    	if(r > cur)
    	{
    		d(i, cur, r);
    		cout << -1 << endl;
    		return 0;
    	}
    	ans[e[i].ss] = {l, r};
    	d(l, r);
    	if(r == n)
    	{
    		l += 1;
    		r = l + 1;
    	}
    	else
    	{
    		if(l == r - 1)
    		{
    			l = 2;
    			r++;
    		}
    		else
    			l++;
    	}
    }

    for(pii &p : ans)
    	cout << p.ff << " " << p.ss << endl;

    end_time = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
    o("\n\n");
    if(elapsed_time<10000)
        o("Elapsed Time: "<<elapsed_time<<" ms\n");
    else
        o("Elapsed Time: "<<elapsed_time/1000<<" s\n");

    return 0;
}


/***
 ** " Love the life you live. Live the life you love. "
 **     -- Bob Marley
***/

/**
  *  Author: dhruv_gheewala
  *  Problem: Lazy Student
  *  Date:   17.04.2020
  *  Time:   00:03:08
**/

#if __has_include("debug.h")
    #include "debug.h"
#else
    #include<bits/stdc++.h>
    using namespace std;

    #define p(str) 7
    #define o(str) 42
    #define fundri 108
    #define d(...) 1729
#endif

#define int long long
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

const bool testcases = 0;
#define ff first
#define ss second
#define endl '\n'
#define all(s) s.begin(),s.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define test int T = 1;if(testcases)cin >> T;for(int tc = 1 ; tc <= T ; tc++)
#define make_unique(vec) sort(all(vec));vec.erase(unique(all(vec)),vec.end())
#define sort_by(cont,expr) sort(all(cont),[&](const auto &lhs,const auto &rhs){return expr;})

ll seed;mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l=0,int r=INT_MAX){return uniform_int_distribution<int>(l,r)(rng);}

template<typename T>bool isPrime(T n){for(T i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}
template<typename T>inline bool in_range(T a,T l,T r){return (a>=l&&a<=r);}

template<typename T,typename U>inline istream& operator >>(istream& in,pair<T,U> &a)
{in>>a.ff>>a.ss;return in;}
template<typename T>inline istream& operator >>(istream& in,vector<T> &a)
{for(auto &x : a)in>>x;return in;}
template<typename TAIL>inline void inp(TAIL& T){cin>>T;}
template<typename HEAD,typename... TAIL>inline void inp(HEAD &H,TAIL&... T){cin>>H;inp(T...);}

int32_t main(int32_t argc, char **argv)
{
    std::chrono::time_point<std::chrono::high_resolution_clock> start_time, end_time;
    start_time = std::chrono::high_resolution_clock::now();

    #ifdef DHRUV_GHEEWALA
        freopen("INPUT.txt","r",stdin);
        freopen("OUTPUT.txt","w",stdout);
        freopen("DEBUG.txt","w",stderr);
    #endif

    fast;
    int n, m, w;
    bool b;

    cin >> n >> m;

    vector<pair<pii, int>> e(m);
    for(int i = 0 ; i < m ; i++)
    {
    	cin >> e[i].ff;
    	e[i].ss = i;
    }

    sort_by(e, lhs.ff.ff == rhs.ff.ff ? lhs.ff.ss > rhs.ff.ss : lhs.ff.ff < rhs.ff.ff);
    d(e);

    vector<pii> ans(m);
    int cur = 1, l = 2, r = 3;

    for(int i = 0 ; i < m ; i++)
    {
    	if(e[i].ff.ss)
    	{
    		cur++;
    		ans[e[i].ss] = {1, cur};
    		continue;
    	}
    	if(r > cur)
    	{
    		d(i, cur, r);
    		cout << -1 << endl;
    		return 0;
    	}
    	ans[e[i].ss] = {l, r};
    	d(l, r);

    	if(l == r - 1)
    	{
    		l = 2;
    		r++;
    	}
    	else
    		l++;
    }

    for(pii &p : ans)
    	cout << p.ff << " " << p.ss << endl;

    end_time = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
    o("\n\n");
    if(elapsed_time<10000)
        o("Elapsed Time: "<<elapsed_time<<" ms\n");
    else
        o("Elapsed Time: "<<elapsed_time/1000<<" s\n");

    return 0;
}


/***
 ** " Love the life you live. Live the life you love. "
 **     -- Bob Marley
***/

/**
  *  Author: dhruv_gheewala
  *  Problem: Lazy Student
  *  Date:   16.04.2020
  *  Time:   23:49:08
**/

#if __has_include("debug.h")
    #include "debug.h"
#else
    #include<bits/stdc++.h>
    using namespace std;

    #define p(str) 7
    #define o(str) 42
    #define fundri 108
    #define d(...) 1729
#endif

#define int long long
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

const bool testcases = 0;
#define ff first
#define ss second
#define endl '\n'
#define all(s) s.begin(),s.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define test int T = 1;if(testcases)cin >> T;for(int tc = 1 ; tc <= T ; tc++)
#define make_unique(vec) sort(all(vec));vec.erase(unique(all(vec)),vec.end())
#define sort_by(cont,expr) sort(all(cont),[&](const auto &lhs,const auto &rhs){return expr;})

ll seed;mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l=0,int r=INT_MAX){return uniform_int_distribution<int>(l,r)(rng);}

template<typename T>bool isPrime(T n){for(T i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}
template<typename T>inline bool in_range(T a,T l,T r){return (a>=l&&a<=r);}

template<typename T,typename U>inline istream& operator >>(istream& in,pair<T,U> &a)
{in>>a.ff>>a.ss;return in;}
template<typename T>inline istream& operator >>(istream& in,vector<T> &a)
{for(auto &x : a)in>>x;return in;}
template<typename TAIL>inline void inp(TAIL& T){cin>>T;}
template<typename HEAD,typename... TAIL>inline void inp(HEAD &H,TAIL&... T){cin>>H;inp(T...);}

int32_t main(int32_t argc, char **argv)
{
    std::chrono::time_point<std::chrono::high_resolution_clock> start_time, end_time;
    start_time = std::chrono::high_resolution_clock::now();

    #ifdef DHRUV_GHEEWALA
        freopen("INPUT.txt","r",stdin);
        freopen("OUTPUT.txt","w",stdout);
        freopen("DEBUG.txt","w",stderr);
    #endif

    fast;
    int n, m, w;
    bool b;

    cin >> n >> m;

    vector<pair<pii, int>> e(m);
    for(int i = 0 ; i < m ; i++)
    {
    	cin >> e[i].ff;
    	e[i].ss = i;
    }

    sort_by(e, lhs.ff == rhs.ff ? lhs.ss > rhs.ss : lhs.ff < rhs.ff);
    d(e);

    vector<pii> ans(m);
    int l = 2, r = 3, cur = 2;

    for(int i = 0 ; i < m ; i++)
    {
    	if(e[i].ff.ss)
    	{
    		ans[e[i].ss] = {1, cur};
    		cur++;
    		continue;
    	}
    	if(r >= cur)
    	{
    		cout << -1 << endl;
    		return 0;
    	}
    	ans[e[i].ss] = {l, r};
    	if(r == n)
    	{
    		l += 1;
    		r = l + 1;
    	}
    	else
    	{
    		r += 1;
    	}
    }

    for(pii &p : ans)
    	cout << p.ff << " " << p.ss << endl;

    end_time = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
    o("\n\n");
    if(elapsed_time<10000)
        o("Elapsed Time: "<<elapsed_time<<" ms\n");
    else
        o("Elapsed Time: "<<elapsed_time/1000<<" s\n");

    return 0;
}


// Problem : D. Lazy Student
// Contest : Codeforces - Codeforces Round #335 (Div. 2)
// URL : https://codeforces.com/contest/606/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long

int n,m;
pii ans[200005];
set<int,greater<int>> e[200005];
vector<pii> ex,in;

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int d,b;
        cin>>d>>b;
        if(b) in.pb({d,i});
        else ex.pb({d,i});
    }
    sort(all(in));
    for(int i=1;i<n;i++){
        ans[in[i-1].se] = {i,i+1};
        e[i+1].insert(in[i-1].fi);
    }
    sort(all(ex));
    int k=0;
    if(ex.empty()) goto here;
    for(int l=2;l<=n-1;l++){
        for(int i=1;i<=n-l;i++){
            int r=i+l;
            if(*e[r].begin() <= ex[k].fi){
                ans[ex[k].se] = {i,r};
                e[r].insert(ex[k++].fi);
            }
            else return cout<<-1<<endl, 0;
            if(k==sz(ex)) break;
        }
        if(k==sz(ex)) break;
    }
    here:
    for(int i=0;i<m;i++) cout<<ans[i].fi<<" "<<ans[i].se<<endl;
    return 0;
}


// Problem : D. Lazy Student
// Contest : Codeforces - Codeforces Round #335 (Div. 2)
// URL : https://codeforces.com/contest/606/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long

int n,m,nxt[200005];
pii ans[200005];
vector<pair<pii,int>> edges;

bool cmp(pair<pii,int> a, pair<pii,int>  b){
    if(a.fi.fi == b.fi.fi && a.fi.se == b.fi.se) return a.se < b.se;
    if(a.fi.fi == b.fi.fi) return a.fi.se < b.fi.se;
    return a.fi.fi < b.fi.fi;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int d,b;
        cin>>d>>b;
        edges.pb({{d,b^1},i});
    }
    sort(all(edges),cmp);
    if(edges[0].fi.se) return cout<<-1<<endl, 0;
    ans[edges[0].se] = {1,2};
    for(int i=1;i<=n;i++) nxt[i] = i+2;
    int en = 2, cur = 1;
    for(int i=1;i<m;i++){
        if(!edges[i].fi.se){
            ans[edges[i].se] = {en,en+1};
            en++;
        }
        else{
            int st = cur;
            if(nxt[st] <= en){
                ans[edges[i].se] = {st,nxt[st]};
                nxt[st]++;
            }
            else{
                if(cur != en) cur++;
                else cur = 1;
                while(cur != st && nxt[cur] > en){
                    if(cur != en) cur++;
                    else cur = 1;
                }
                if(cur == st) return cout<<-1<<endl, 0;
                ans[edges[i].se] = {cur,nxt[cur]};
                nxt[cur]++;
            }
        }
    }
    for(int i=0;i<m;i++) cout<<ans[i].fi<<" "<<ans[i].se<<endl;
    return 0;
}


// Problem : D. Lazy Student
// Contest : Codeforces - Codeforces Round #335 (Div. 2)
// URL : https://codeforces.com/contest/606/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long

int n,m;
pii ans[200005];
set<int,greater<int>> e[200005];
vector<pii> ex,in;

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int d,b;
        cin>>d>>b;
        if(b) in.pb({d,i});
        else ex.pb({d,i});
    }
    sort(all(in));
    for(int i=1;i<n;i++){
        ans[in[i-1].se] = {i,i+1};
        e[i+1].insert(in[i-1].fi);
    }
    sort(all(ex));
    int k=0;
    for(int l=2;l<=n-1;l++){
        for(int i=1;i<=n-l;i++){
            int r=i+l;
            if(*e[r].begin() <= ex[k].fi){
                ans[ex[k].se] = {i,r};
                e[r].insert(ex[k++].fi);
            }
            else return cout<<-1<<endl, 0;
            if(k==sz(ex)) break;
        }
        if(k==sz(ex)) break;
    }
    for(int i=0;i<m;i++) cout<<ans[i].fi<<" "<<ans[i].se<<endl;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N,M; cin >> N >> M;

    vector<pair<PII,int>> E(M),O(M);
    REP(i,M){
        int a,b; cin >> a >> b;
        O[i] = make_pair(PII(a,b),i);
        b ^= 1;
        E[i] = make_pair(PII(a,b),i);
    }
    sort(E.begin(),E.end());
    vector<PII> ans(M);
    vector<PII> dic;
    FOR(i,1,1010){
        for(int j = i-1; j > 1; j--){
            dic.eb(j,i);
        }
    }

    int node = 1;
    int used = 0;
    int used2 = 0;
    for(auto p : E){
        if(p.first.second == 0){ //MST
            node++;
            used++;
            ans[p.second] = PII(1,node);
        }else{
            if(1LL * node * (node-1) / 2 > used){
                used++;
                used2++;
                ans[p.second] = dic[used2-1];
            }else{
                cout << -1 << endl;
                return 0;
            }
        }
    }
    for(auto p : ans){
        cout << p.first << " " << p.second << endl;
    }

}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N,M; cin >> N >> M;

    vector<pair<PII,int>> E(M),O(M);
    REP(i,M){
        int a,b; cin >> a >> b;
        O[i] = make_pair(PII(a,b),i);
        b ^= 1;
        E[i] = make_pair(PII(a,b),i);
    }
    sort(E.begin(),E.end());
    vector<PII> ans(M);
    vector<PII> dic;
    FOR(i,1,1010){
        for(int j = i-1; j > 1; j--){
            dic.eb(j,i);
        }
    }

    int node = 1;
    int used = 0;
    int used2 = 0;
    for(auto p : E){
        if(p.first.second == 0){ //MST
            node++;
            used++;
            ans[p.second] = PII(1,node);
        }else{
            if(1LL * node * (node-1) / 2 > used){
                used++;
                used2++;
                ans[p.second] = dic[used2];
            }else{
                cout << -1 << endl;
                return 0;
            }
        }
    }
    for(auto p : ans){
        cout << p.first << " " << p.second << endl;
    }

}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N,M; cin >> N >> M;

    vector<pair<PII,int>> E(M),O(M);
    REP(i,M){
        int a,b; cin >> a >> b;
        O[i] = make_pair(PII(a,b),i);
        b ^= 1;
        E[i] = make_pair(PII(a,b),i);
    }
    sort(E.begin(),E.end());
    vector<PII> ans(M);
    vector<PII> dic;
    FOR(i,1,1010){
        for(int j = i-1; j > 1; j--){
            dic.eb(j,i);
        }
    }

    int node = 1;
    int used = 0;
    int used2 = 0;
    for(auto p : E){
        if(p.first.second == 0){ //MST
            node++;
            used++;
            ans[p.second] = PII(1,node);
        }else{
            if(1LL * node * (node+1) / 2 > used){
                used++;
                used2++;
                ans[p.second] = dic[used2];
            }else{
                cout << -1 << endl;
                return 0;
            }
        }
    }
    for(auto p : ans){
        cout << p.first << " " << p.second << endl;
    }

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <unistd.h>
using namespace std;
using namespace __gnu_pbds;
//#define int                 long long
#define ll                  long long
#define ld                  double
#define rep(i,n)            for(int i=0;i<n;i++)
#define hell                1000000007LL
#define inf                 (double)1e15
#define vi                  vector<int>
#define vii                 vector< vi >
#define pb                  push_back
#define mp                  make_pair
#define fi                  first
#define se                  second
#define pii                 pair<int,int>
#define all(c)              c.begin(),c.end()
#define sz(c)               (int)c.size()
#define hash1               105727LL
#define hash2               hell
#define eps                 1e-10
//#define pi                  3.141592653589793238462643383279502884197
typedef tree<pair<int,int>,null_type,less<pair<int,int> >,
rb_tree_tag,tree_order_statistics_node_update> statisticsTree;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
ll power(ll x, ll y,ll p)
{
	ll res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
			res=((res%p)*(x%p))%p;
		y=y>>1;
		x=((x%p)*(x%p))%p;
	}
	return res;
}
ll raichu(ll x,ll y)
{
	ll res=1;
	while(y>0)
	{
		if(y&1)
			res=((res)*(x));
		y=y>>1;
		x=((x)*(x));
	}
	return res;
}
bool isprime(ll n)
{
	if(n<2) return false;
	else if(n==2) return true;
	else if(n%2==0) return false;
	else
	{
		ll z=sqrt(n);
		rep(i,z-1) if(n%(i+2)==0) return false;
		return true;
	}
}
int32_t main()
{
	//freopen("B-large.in","r",stdin);
	//freopen("out4.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1,Tests;
	//cin>>tests;
	Tests=tests;
	while(tests--)
	{
		int n,m;
		cin>>n>>m;
		vector<pii > span,edges;
		rep(i,m)
		{
			int a,b;
			cin>>a>>b;
			if(b==1) span.pb(mp(a,i));
			else edges.pb(mp(a,i));
		}
		sort(all(span));
		sort(all(edges));
		int idx=0;
		vector<pii > ans(m);
		rep(i,n-1)
		{
			ans[span[i].se]=mp(1,i+2);
		}
		rep(i,n-1)
		{
			int it=0;
			while(idx<sz(edges) && i+it+1<n-1 && edges[idx].fi>=span[i+1+it].fi)
			{
				ans[edges[idx].se]=mp(i+2,i+1+it+2);
				idx++;
				it++;
			}
		}
		if(idx==sz(edges))
		{
			rep(i,m) cout<<ans[i].fi<<" "<<ans[i].se<<endl;
		}
		else cout<<-1;
	}
	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <unistd.h>
using namespace std;
using namespace __gnu_pbds;
//#define int                 long long
#define ll                  long long
#define ld                  double
#define rep(i,n)            for(int i=0;i<n;i++)
#define hell                1000000007LL
#define inf                 (double)1e15
#define vi                  vector<int>
#define vii                 vector< vi >
#define pb                  push_back
#define mp                  make_pair
#define fi                  first
#define se                  second
#define pii                 pair<int,int>
#define all(c)              c.begin(),c.end()
#define sz(c)               (int)c.size()
#define hash1               105727LL
#define hash2               hell
#define eps                 1e-10
//#define pi                  3.141592653589793238462643383279502884197
typedef tree<pair<int,int>,null_type,less<pair<int,int> >,
rb_tree_tag,tree_order_statistics_node_update> statisticsTree;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
ll power(ll x, ll y,ll p)
{
	ll res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
			res=((res%p)*(x%p))%p;
		y=y>>1;
		x=((x%p)*(x%p))%p;
	}
	return res;
}
ll raichu(ll x,ll y)
{
	ll res=1;
	while(y>0)
	{
		if(y&1)
			res=((res)*(x));
		y=y>>1;
		x=((x)*(x));
	}
	return res;
}
bool isprime(ll n)
{
	if(n<2) return false;
	else if(n==2) return true;
	else if(n%2==0) return false;
	else
	{
		ll z=sqrt(n);
		rep(i,z-1) if(n%(i+2)==0) return false;
		return true;
	}
}
int32_t main()
{
	//freopen("B-large.in","r",stdin);
	//freopen("out4.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1,Tests;
	//cin>>tests;
	Tests=tests;
	while(tests--)
	{
		int n,m;
		cin>>n>>m;
		vector<pii > span,edges;
		rep(i,m)
		{
			int a,b;
			cin>>a>>b;
			if(b==1) span.pb(mp(a,i));
			else edges.pb(mp(a,i));
		}
		sort(all(span));
		sort(all(edges));
		int idx=0;
		vector<pii > ans(m);
		rep(i,n-1)
		{
			ans[span[i].se]=mp(1,i+2);
		}
		rep(i,n-2)
		{
			int it=0;
			//cout<<edges[idx].fi<<endl;
			while(idx<sz(edges) && it<i+1 && edges[idx].fi>=span[i+1].fi)
			{
				//cout<<idx<<" "<<i<<" "<<span[i+1+it].fi<<endl;
				ans[edges[idx].se]=mp(i+3,it+2);
				idx++;
				it++;
			}
		}
		if(idx==sz(edges))
		{
			rep(i,m) cout<<ans[i].fi<<" "<<ans[i].se<<endl;
		}
		else cout<<-1;
	}
	return 0;
}


/***from dust i have come, dust i will be***/

#include<bits/stdc++.h>

typedef long long int ll;
typedef unsigned long long int ull;

#define dbg printf("in\n")
#define nl printf("\n")
#define N 101010
#define inf 1e9

#define sf(n) scanf("%d", &n)
#define sff(n,m) scanf("%d%d",&n,&m)
#define sfl(n) scanf("%I64d", &n)
#define sffl(n,m) scanf("%I64d%I64d",&n,&m)

#define pf(n) printf("%d",n)
#define pff(n,m) printf("%d %d",n,m)
#define pffl(n,m) printf("%I64d %I64d",n,m)
#define pfl(n) printf("%I64d",n)
#define pfs(s) printf("%s",s)

#define pb push_back
#define pp pair<int, int>

#define white 0
#define grey 1
#define black 2

using namespace std;

int node[N];
bool cmp(pair<pp, int> a, pair<pp, int> b)
{
    if(a.first.first == b.first.first)
        return a.first.second > b.first.second;

    return a.first.first < b.first.first;
}

int main()
{
    // freopen("in.txt", "r", stdin);

    int i, j, k;
    int n, m, t;

    sff(n, m);
    vector<pair<pp, int>> vec;

    for(i = 0; i < m; i++)
    {
        sff(t, k);
        vec.pb({{t, k}, i});
    }

    queue<int> q;
    for(i = 1; i <= n; i++)
        node[i] = i + 2, q.push(i);

    sort(vec.begin(), vec.end(), cmp);

    vector<pp> ans(m);
    k = 1;
    int done = 1;

    for(i = 0; i < m; i++)
    {
        if(vec[i].first.second)
            ans[vec[i].second] = {k, k + 1}, k++, done++;

        else
        {
            while(q.size())
            {
                if(node[q.front()] > n || node[q.front()] > done)
                    q.pop();

                else break;
            }

            if(q.size())
                ans[vec[i].second] = {q.front(), node[q.front()]}, node[q.front()]++;
            else{
                pf(-1);
                return 0;
            }
        }
    }

    for(pp e : ans)
        pff(e.first, e.second), nl;

    return 0;
}


/***from dust i have come, dust i will be***/

#include<bits/stdc++.h>

typedef long long int ll;
typedef unsigned long long int ull;

#define dbg printf("in\n")
#define nl printf("\n")
#define N 101010
#define inf 1e9

#define sf(n) scanf("%d", &n)
#define sff(n,m) scanf("%d%d",&n,&m)
#define sfl(n) scanf("%I64d", &n)
#define sffl(n,m) scanf("%I64d%I64d",&n,&m)

#define pf(n) printf("%d",n)
#define pff(n,m) printf("%d %d",n,m)
#define pffl(n,m) printf("%I64d %I64d",n,m)
#define pfl(n) printf("%I64d",n)
#define pfs(s) printf("%s",s)

#define pb push_back
#define pp pair<int, int>

#define white 0
#define grey 1
#define black 2

using namespace std;

int node[N];
bool cmp(pair<pp, int> a, pair<pp, int> b)
{
    if(a.first.first == b.first.first)
        return a.first.second > b.first.second;

    return a.first.first < b.first.first;
}

int main()
{
    // freopen("in.txt", "r", stdin);

    int i, j, k;
    int n, m, t;

    sff(n, m);
    vector<pair<pp, int>> vec;

    for(i = 0; i < m; i++)
    {
        sff(t, k);
        vec.pb({{t, k}, i});
    }

    queue<int> q;
    for(i = 1; i <= n; i++)
        node[i] = i + 2, q.push(i);

    sort(vec.begin(), vec.end(), cmp);

    vector<pp> ans(m);
    k = 1;
    int done = 1;

    for(i = 0; i < m; i++)
    {
        //cout<<vec[i].first.first<<" "<<vec[i].first.second, nl;
        //cout<<"cnt of 1: "<<node[1]<<endl;
        if(vec[i].first.second)
            ans[vec[i].second] = {k, k + 1}, k++, done++;

        else
        {
            queue<int> addLater;
            while(q.size())
            {
                if(node[q.front()] > n || node[q.front()] > done)
                {
                    //cout<<q.front()<<" "<<node[q.front()]<<" "<<done<<endl;
                    addLater.push(q.front());
                    q.pop();
                }

                else break;
            }

            if(q.size())
                ans[vec[i].second] = {q.front(), node[q.front()]}, node[q.front()]++;

            else { pf(-1); return 0; }

            while(addLater.size())
                q.push(addLater.front()), addLater.pop();
        }
    }

    for(pp e : ans)
        pff(e.first, e.second), nl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define clr(a,b) memset(a,b,sizeof(a))
#define all(v) ((v).begin()),((v).end())
#define read(v) freopen(v, "r", stdin)
#define write(v) freopen(v, "wt", stdout)
#define fastIO cout << fixed << setprecision(0), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-9, PI = acos(-1);
const int N = 2e5 + 9, M = 1e2 + 9, OO = 1e8 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

vector<pair<int, int>> mst,cycles, rest;
vector<pair<int, pair<int, int>>> vec;
vector<int> wa7ed;
pair<int, int> ans[N];

void buildGraph(int n) {
  for (int i = 2; i <= n; ++i)
    mst.push_back({i-1, i});
  for (int i = 1; i <= n; ++i)
    for (int j = i + 2; j < n; ++j)
      cycles.push_back({i, j});
  for (int i = 2; i < n; ++i)
    rest.push_back({i - 1, n});

}

int main() {
  fastIO;
//  read("input.in");
//  write("input.in");
  vector<int> w;
  ll n, m, a, b;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    w.push_back(a);
    vec.push_back({a, {b, i}});
    if(b)
      wa7ed.push_back(a);
  }
  multiset<int> st;
  sort(all(w));
  ll k = n - 3;
  ll rem = (n-1) + ((k) * (k+1)) / 2;
  for (int i = 0; i < rem; ++i)
    st.insert(w[i]);
  bool can = 1;
  for(int it: wa7ed) {
    if(st.find(it) == st.end()) {
      can = 0;
      break;
    }
    st.erase(st.lower_bound(it));
  }
  if(can) {
    buildGraph(n);
    sort(all(vec));
    for (int i = 0; i < m; ++i) {
      if(vec[i].second.first) {
        ans[vec[i].second.second] = mst.back();
        mst.pop_back();
      } else {
        if(!cycles.empty()) {
          ans[vec[i].second.second] = cycles.back();
          cycles.pop_back();
        } else {
          ans[vec[i].second.second] = rest.back();
          rest.pop_back();
        }
      }
    }
    for (int i = 0; i < m; ++i)
      cout << ans[i].first << ' '<< ans[i].second << '\n';
  } else
    cout << -1;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define clr(a,b) memset(a,b,sizeof(a))
#define all(v) ((v).begin()),((v).end())
#define read(v) freopen(v, "r", stdin)
#define write(v) freopen(v, "wt", stdout)
#define fastIO cout << fixed << setprecision(0), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-9, PI = acos(-1);
const int N = 2e5 + 9, M = 1e2 + 9, OO = 1e8 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

vector<pair<int, int>> mst,cycles, rest;
vector<pair<int, pair<int, int>>> vec;
vector<int> wa7ed;
pair<int, int> ans[N];

void buildGraph(int n) {
  for (int i = 2; i <= n; ++i)
    mst.push_back({i-1, i});
  for (int i = 1; i <= n; ++i)
    for (int j = i + 2; j < n; ++j)
      cycles.push_back({i, j});
  for (int i = 2; i < n; ++i)
    rest.push_back({i - 1, n});

}

int main() {
  fastIO;
//  read("input.in");
//  write("input.in");
  vector<int> w;
  ll n, m, a, b;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    w.push_back(a);
    vec.push_back({a, {b, i}});
    if(b)
      wa7ed.push_back(a);
  }
  multiset<int> st;
  sort(all(w));
  ll k = n - 3;
  ll rem = (n-1) + ((k) * (k-1)) / 2;
  for (int i = 0; i < rem; ++i)
    st.insert(w[i]);
  bool can = 1;
  for(int it: wa7ed) {
    if(st.find(it) == st.end()) {
      can = 0;
      break;
    }
    st.erase(st.lower_bound(it));
  }
  if(can) {
    buildGraph(n);
    sort(all(vec));
    for (int i = 0; i < m; ++i) {
      if(vec[i].second.first) {
        ans[vec[i].second.second] = mst.back();
        mst.pop_back();
      } else {
        if(!cycles.empty()) {
          ans[vec[i].second.second] = cycles.back();
          cycles.pop_back();
        } else {
          ans[vec[i].second.second] = rest.back();
          rest.pop_back();
        }
      }
    }
    for (int i = 0; i < m; ++i)
      cout << ans[i].first << ' '<< ans[i].second << '\n';
  } else
    cout << -1;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define clr(a,b) memset(a,b,sizeof(a))
#define all(v) ((v).begin()),((v).end())
#define read(v) freopen(v, "r", stdin)
#define write(v) freopen(v, "wt", stdout)
#define fastIO cout << fixed << setprecision(0), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-9, PI = acos(-1);
const int N = 2e5 + 9, M = 1e2 + 9, OO = 1e8 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

vector<pair<int, pair<int, int>>> vec;
pair<int, int> ans[N];

int main() {
  fastIO;
//  read("input.in");
//  write("input.in");
  vector<int> w;
  ll n,
  m, a, b;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    vec.push_back( { a, { b ^ 1, i } });
  }
  sort(all(vec));
  int from = 3, to = 2, dist = 2;
  for (int i = 0; i < m; ++i) {
    if (!vec[i].second.first)
      ans[vec[i].second.second] = {1, dist++};
      else {
        if(from >= dist) {
          cout << -1;
          return 0;
        }
        ans[vec[i].second.second] = {from, to};
        ++to;
        if(from == to)
          ++from, to = 2;
      }
    }
  for (int i = 0; i < m; ++i)
    cout << ans[i].first << ' ' << ans[i].second << '\n';
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int, int>
int a[100005], b[100005];
int N, M;
int ct = 0;
int ans[100005][2];
int mnW = INT_MAX, mnIdx = -1;
vector<ii> v;
vector<ii> v2;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> N >> M;
    for (int i = 1; i <= M; i++) {
        cin >> a[i] >> b[i];
        if (b[i] == 1) {
            v.push_back({a[i], i});
        } else {
            v2.push_back({a[i], i});
        }
    }

    sort(v.begin(), v.end());
    sort(v2.begin(), v2.end());

    for (int i = 0; i < v.size(); i++) {
        ans[v[i].second][0] = i + 1;
        ans[v[i].second][1] = i + 2;
    }

    int l = 0, r = 2;
    for (auto p : v2) {
        if (r > v.size()) {
            cout << -1 << endl;
            return 0;
        }
        if (r < v.size() && v[r].first > p.first) {
            cout << -1 << endl;
            return 0;
        }
        if (v[r - 1].first > p.first) {
            cout << -1 << endl;
            return 0;
        }
        ans[p.second][0] = l + 1;
        ans[p.second][1] = r + 1;
        r++;
        if (r > v.size()) {
            l++;
            r = l + 2;
        }
    }
    for (int i = 1; i <= M; i++) {
        cout << ans[i][0] << " " << ans[i][1] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int, int>
int a[100005], b[100005];
int N, M;
int ct = 0;
int ans[100005][2];
int mnW = INT_MAX, mnIdx = -1;
vector<ii> v;
vector<ii> v2;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> N >> M;
    for (int i = 1; i <= M; i++) {
        cin >> a[i] >> b[i];
        if (b[i] == 1) {
            v.push_back({a[i], i});
        } else {
            v2.push_back({a[i], i});
        }
    }

    sort(v.begin(), v.end());
    sort(v2.begin(), v2.end());

    for (int i = 0; i < v.size(); i++) {
        ans[v[i].second][0] = i + 1;
        ans[v[i].second][1] = i + 2;
    }

    int l = 0, r = 2;
    for (auto p : v2) {
        if (r > v.size()) {
            cout << -1 << endl;
            return 0;
        }

        if (v[r - 1].first > p.first) {
            cout << -1 << endl;
            return 0;
        }
        ans[p.second][0] = l + 1;
        ans[p.second][1] = r + 1;
        l++;
        if (l == r - 1) {
            l = 0;
            r++;
        }
    }
    for (int i = 1; i <= M; i++) {
        cout << ans[i][0] << " " << ans[i][1] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int, int>
int a[100005], b[100005];
int N, M;
int ct = 0;
int ans[100005][2];
int mnW = INT_MAX, mnIdx = -1;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> N >> M;
    for (int i = 1; i <= M; i++) {
        cin >> a[i] >> b[i];
        if (b[i] == 1) {
            ct++;
            if (a[i] < mnW) {
                mnW = a[i];
                mnIdx = ct;
            }
            ans[i][0] = ct;
            ans[i][1] = ct + 1;
        }
    }
    for (int i = 1; i <= M; i++) {
        if (b[i] == 0 && a[i] < mnW) {
            cout << -1 << endl;
            return 0;
        }
    }
    for (int i = 1; i <= M; i++) {
        if (b[i] == 0) {
            ans[i][0] = mnIdx;
            ans[i][1] = mnIdx + 1;
        }
    }
    for (int i = 1; i <= M; i++) {
        cout << ans[i][0] << " " << ans[i][1] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int, int>
int a[100005], b[100005];
int N, M;
int ct = 0;
int ans[100005][2];
int mnW = INT_MAX, mnIdx = -1;
vector<ii> v;
vector<ii> v2;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> N >> M;
    for (int i = 1; i <= M; i++) {
        cin >> a[i] >> b[i];
        if (b[i] == 1) {
            v.push_back({a[i], i});
        } else {
            v2.push_back({a[i], i});
        }
    }

    sort(v.begin(), v.end());
    sort(v2.begin(), v2.end());

    for (int i = 0; i < v.size(); i++) {
        ans[v[i].second][0] = i + 1;
        ans[v[i].second][1] = i + 2;
    }

    int l = 0, r = 2;
    for (auto p : v2) {
        if (r > v.size()) {
            cout << -1 << endl;
            return 0;
        }

        if (v[r - 1].first > p.first) {
            cout << -1 << endl;
            return 0;
        }
        ans[p.second][0] = l + 1;
        ans[p.second][1] = r + 1;
        r++;
        if (r > v.size()) {
            l++;
            r = l + 2;
        }
    }
    for (int i = 1; i <= M; i++) {
        cout << ans[i][0] << " " << ans[i][1] << endl;
    }

    return 0;
}


// Problem : D. Lazy Student
// Contest : Codeforces - Codeforces Round #335 (Div. 2)
// URL : https://codeforces.com/contest/606/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 100005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub uppper_bound
using namespace std;
bool compare(pp a,pp b)
{
	if(a.ss < b.ss)
	return false;
	else if(a.ss > b.ss)
	return true;
	else{
		if(a.ff < b.ff)
		return true;
		return false;
	}
}
map<pp,vector<int> > mp;
map<int,pp> mp1;
void solve()
{
	int n,m;
	cin >> n >> m;
	pp arr[m];
	rep(i,0,m)
	{
		int x,y;
		cin >> x >> y;
		arr[i]={x,y};
		mp[{x,y}].pb(i);
	}
	sort(arr,arr+m,compare);
	int maxi=arr[0].ff;
	rep(i,0,n-1)
	{
		mp1[mp[arr[i]].back()]={i+1,i+2};
		mp[arr[i]].pop_back();
	}
	int j=1;
	int i=n-1;
	while(i<m and j<n-1)
	{
		maxi=arr[j].ff;
		for(int k=j-1;k>=0;k--)
		{
			if(arr[i].ff >= maxi)
			{
				mp1[mp[arr[i]].back()]={j+2,k+1};
				mp[arr[i]].pop_back();
				i++;
			}
			else{
				break;
			}
			if(i==m)
			break;
		}
		j++;
	}
	if(i < m)
	{
		cout << -1;
		return;
	}
	for(int i=0;i<m;i++)
	{
		cout << mp1[i].ff <<" "<< mp1[i].ss<<"\n";
	}
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


// Problem : D. Lazy Student
// Contest : Codeforces - Codeforces Round #335 (Div. 2)
// URL : https://codeforces.com/contest/606/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 100005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub uppper_bound
using namespace std;
bool compare(pp a,pp b)
{
	if(a.ss < b.ss)
	return false;
	else if(a.ss > b.ss)
	return true;
	else{
		if(a.ff < b.ff)
		return true;
		return false;
	}
}
map<pp,int> mp;
map<int,pp> mp1;
void solve()
{
	int n,m;
	cin >> n >> m;
	pp arr[m];
	rep(i,0,m)
	{
		int x,y;
		cin >> x >> y;
		arr[i]={x,y};
		mp[{x,y}]=i;
	}
	sort(arr,arr+n,compare);
	int maxi=arr[0].ff;
	rep(i,0,n-1)
	{
		mp1[mp[arr[i]]]={i+1,i+2};
	}
	int j=1;
	int i=n-1;
	while(i<m and j<n-1)
	{
		maxi=arr[j].ff;
		for(int k=j-1;k>=0;k--)
		{
			if(arr[i].ff >= maxi)
			{
				mp1[mp[arr[i]]]={j+2,k+1};
				i++;
			}
			else{
				break;
			}
			if(i==m)
			break;
		}
		j++;
	}
	if(i < m)
	{
		cout << -1;
		return;
	}
	for(auto it=mp1.begin();it!=mp1.end();it++)
	{
		cout << it->ss.ff <<" "<< it->ss.ss <<"\n";
	}
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


// Problem : D. Lazy Student
// Contest : Codeforces - Codeforces Round #335 (Div. 2)
// URL : https://codeforces.com/contest/606/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 100005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub uppper_bound
using namespace std;
bool compare(pp a,pp b)
{
	if(a.ss < b.ss)
	return false;
	else if(a.ss > b.ss)
	return true;
	else{
		if(a.ff < b.ff)
		return true;
		return false;
	}
}
map<pp,int> mp;
map<int,pp> mp1;
void solve()
{
	int n,m;
	cin >> n >> m;
	pp arr[m];
	rep(i,0,m)
	{
		int x,y;
		cin >> x >> y;
		arr[i]={x,y};
		mp[{x,y}]=i;
	}
	sort(arr,arr+m,compare);
	int maxi=arr[0].ff;
	rep(i,0,n-1)
	{
		mp1[mp[arr[i]]]={i+1,i+2};
	}
	int j=1;
	int i=n-1;
	while(i<m and j<n-1)
	{
		maxi=arr[j].ff;
		for(int k=j-1;k>=0;k--)
		{
			if(arr[i].ff >= maxi)
			{
				mp1[mp[arr[i]]]={j+2,k+1};
				i++;
			}
			else{
				break;
			}
			if(i==m)
			break;
		}
		j++;
	}
	if(i < m)
	{
		cout << -1;
		return;
	}
	for(auto it=mp1.begin();it!=mp1.end();it++)
	{
		cout << it->ss.ff <<" "<< it->ss.ss <<"\n";
	}
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define rf(i, a, b) for (int(i) = (a); (i) <= (b); (i)++)
#define rb(i, b, a) for (int(i) = (b); (i) >= (a); (i)--)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;

const int N = 1e5 + 1;
const int INF = 2e9;

int n, m;
ii ans[N];
vector<iii> edge;
set<int> connected[N];
int smallest = 2;
int pos = 2;
int cur = 2;

int find() {
    if(smallest >= cur) return -1;
    while (connected[smallest].find(pos) != connected[smallest].end()) {
        pos++;
        if (pos >= cur) {
            smallest++;
            pos = 2;
            return find();
        }
    }
    return pos;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    rf(i, 1, m) {
        connected[i].insert(i);
        int a, b;
        cin >> a >> b;
        edge.pb({{a, 1 - b}, i});
    }
    sort(all(edge));
    for (iii e : edge) {
        int idx = e.second;
        if (e.first.second == 0) {
            connected[1].insert(cur);
            connected[cur].insert(1);
            ans[idx] = {1, cur++};
        } else {
            int next = find();
            if(next == -1)
                return cout << -1 << "\n", 0;
            ans[idx] = {smallest, next};
            connected[smallest].insert(next);
            connected[next].insert(smallest);
        }
    }
    rf(i, 1, m) cout << ans[i].first << " " << ans[i].second << "\n";
}


#include <bits/stdc++.h>

#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define rf(i, a, b) for (int(i) = (a); (i) <= (b); (i)++)
#define rb(i, b, a) for (int(i) = (b); (i) >= (a); (i)--)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;

const int N = 1e5 + 1;
const int INF = 2e9;

int n, m;
ii ans[N];
vector<iii> edge;
set<int> connected[N];
int smallest = 2;
int pos = 2;

int find() {
    while (connected[smallest].find(pos) != connected[smallest].end()) {
        pos++;
        if (pos > n) {
            smallest++;
            pos = 2;
            return find();
        }
    }
    return pos;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    rf(i, 1, m) {
        connected[i].insert(i);
        int a, b;
        cin >> a >> b;
        edge.pb({{a, 1 - b}, i});
    }
    sort(all(edge));
    int cur = 2;
    for (iii e : edge) {
        int idx = e.second;
        if (e.first.second == 0) {
            connected[1].insert(cur);
            connected[cur].insert(1);
            ans[idx] = {1, cur++};
        } else {
            int next = find();
            if (next >= cur || smallest >= cur)
                return cout << -1 << "\n", 0;
            ans[idx] = {smallest, next};
            connected[smallest].insert(next);
            connected[next].insert(smallest);
        }
    }
    rf(i, 1, m) cout << ans[i].first << " " << ans[i].second << "\n";
}


#include <bits/stdc++.h>

#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define rf(i, a, b) for (int(i) = (a); (i) <= (b); (i)++)
#define rb(i, b, a) for (int(i) = (b); (i) >= (a); (i)--)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;

const int N = 1e5 + 1;
const int INF = 2e9;

int n, m;
ii ans[N];
vector<iii> edge;
set<int> connected[N];
int smallest = 2;
int pos = 2;
int find() {
    while (connected[smallest].find(pos) != connected[smallest].end()) {
        pos++;
        if (pos > n) {
            smallest++;
            pos = 2;
            return find();
        }
    }
    return pos;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    rf(i, 1, m) {
        connected[i].insert(i);
        int a, b;
        cin >> a >> b;
        edge.pb({{a, b}, i});
    }
    sort(all(edge));
    int cur = 2;
    for (iii e : edge) {
        int idx = e.second;
        if (e.first.second == 1) {
            connected[1].insert(cur);
            connected[cur].insert(1);
            ans[idx] = {1, cur++};
        } else {
            int next = find();
            if (next >= cur)
                return cout << -1 << "\n", 0;
            ans[idx] = {smallest, next};
            connected[smallest].insert(next);
            connected[next].insert(smallest);
        }
    }
    rf(i, 1, m) cout << ans[i].first << " " << ans[i].second << "\n";
}


#include <bits/stdc++.h>

#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define rf(i, a, b) for (int(i) = (a); (i) <= (b); (i)++)
#define rb(i, b, a) for (int(i) = (b); (i) >= (a); (i)--)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;

const int N = 1e5 + 1;
const int INF = 2e9;

int n, m;
ii ans[N];
vector<iii> edge;
set<int> connected[N];
int smallest = 2;
int pos = 2;
int find() {
    while (connected[smallest].find(pos) != connected[smallest].end()) {
        pos++;
        if (pos > n) {
            smallest++;
            pos = 2;
            return find();
        }
    }
    return pos;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    rf(i, 1, m) {
        connected[i].insert(i);
        int a, b;
        cin >> a >> b;
        edge.pb({{a, b}, i});
    }
    sort(all(edge));
    int cur = 2;
    for (iii e : edge) {
        int idx = e.second;
        if (e.first.second == 1) {
            connected[1].insert(cur);
            connected[cur].insert(1);
            ans[idx] = {1, cur++};
        } else {
            int next = find();
            if (next >= cur || smallest >= cur)
                return cout << -1 << "\n", 0;
            ans[idx] = {smallest, next};
            connected[smallest].insert(next);
            connected[next].insert(smallest);
        }
    }
    rf(i, 1, m) cout << ans[i].first << " " << ans[i].second << "\n";
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;

int n, m;

vector<pair<pair<int,int>,int>> edges;
pair<int,int> ans[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>m;
    for (int i=0; i<m; i++) {
	int wei,b; cin>>wei>>b;
	b=b^1;
	edges.push_back({ {wei,b}, i});
    }

    sort(edges.begin(), edges.end());

    int x=1;
    int a=1;
    int b=3;

    for (auto ed: edges) {
	int id = ed.second;
	if (ed.first.second==0) {
	    ans[id] = {x,x+1};
	    x++;
	} else {
	    if (b>x) out(-1);
	    ans[id] = {a,b};
	    a++;
	    if (a+1==b) {
		a=1;
		b++;
	    }
	}
    }

    for (int i=0; i<m; i++) {
	cout<<ans[i].first<<" "<<ans[i].second<<"\n";
    }

    return 0;
}


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

typedef long long ll;
typedef long double ld;

const int N=100100;
int n,m;
int con[N];
int l[N],r[N];
vector<pair<int,int>>inc,ninc; // w,idx
main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>n>>m;
	for(int i=0;i<m;++i){
		int w,in;cin>>w>>in;
		if(in)inc.push_back({w,i});
		else ninc.push_back({w,i});
	}
	sort(inc.begin(),inc.end());
	sort(ninc.begin(),ninc.end());
	for(int i=1;i<n;++i){
		con[i]=inc[i-1].first;
		l[inc[i-1].second]=i-1;
		r[inc[i-1].second]=i;
	}
	int last=0;
	for(int i=0;i<n&&last<ninc.size();++i){
		int j=i+2;
		while(j<n&&last<ninc.size()&&con[j]<=ninc[last].first){
			l[ninc[last].second]=i;
			r[ninc[last].second]=j;
			++last;
			++j;
		}
	}
	if(last!=ninc.size()){cout<<-1<<endl;return 0;}
	for(int i=0;i<m;++i)cout<<l[i]+1<<" "<<r[i]+1<<endl;
}


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

typedef long long ll;
typedef long double ld;

const int N=100100;
int n,m;
int con[N];
int l[N],r[N];
vector<pair<int,int>>inc,ninc; // w,idx
main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>n>>m;
	for(int i=0;i<m;++i){
		int w,in;cin>>w>>in;
		if(in)inc.push_back({w,i});
		else ninc.push_back({w,i});
	}
	sort(inc.begin(),inc.end());
	sort(ninc.begin(),ninc.end());
	for(int i=1;i<n;++i){
		con[i]=inc[i-1].first;
		l[inc[i-1].second]=i-1;
		r[inc[i-1].second]=i;
	}
	int last=0;
	for(int i=0;i<n&&last<ninc.size();++i){
		for(int j=i-2;j>=0&&last<ninc.size()&&con[i]<=ninc[last].first;--j,++last){
			l[ninc[last].second]=i;
			r[ninc[last].second]=j;
		}
	}
	if(last!=ninc.size()){cout<<-1<<endl;return 0;}
	for(int i=0;i<m;++i)cout<<l[i]+1<<" "<<r[i]+1<<endl;
}


#include<cstdio>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<map>
#include<cctype>
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define mem(a,x) memset(a,x,sizeof(a))
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid + 1,r
#define P pair<int, int>
#define ull unsigned long long
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
const ll mod = 998244353;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-7;
ll GCD(ll a, ll b) { while (b ^= a ^= b ^= a %= b); return a; }
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
ll prime[maxn] = { 0 }, num_prime = 0;
int isNotPrime[maxn] = { 1 , 1 };
inline ll read()
{
	ll X = 0, w = 0; char ch = 0;
	while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }
	while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
	return w ? -X : X;
}
inline void write(int x)
{
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
void isPrime()
{
	for (int i = 2; i < maxn; ++i)
	{
		if (!isNotPrime[i]) prime[num_prime++] = i;
		for (int j = 0; j < num_prime && i * prime[j] < maxn; ++j)
		{
			isNotPrime[i * prime[j]] = 1;
			if (!i % prime[j]) break;
		}
	}
	printf("%lld", prime[num_prime - 1]);
}
ll binaryPow(ll a, ll b, ll c) {
	ll ans = 1;
	while (b > 0) {
		if (b & 1) {
			ans = ans * a % c;
		}
		a = a * a % c;
		b >>= 1;
	}
	return ans % c;
}
void BUG()
{
	printf("DEBUG\n");
}
struct node
{
	int val;
	int vis;
	int u, v;
	int num;
}g[maxn];
int use[maxn];
int cmp1(const node& a, const node& b)
{
	return a.num < b.num;
}
int cmp(const node& a, const node& b)
{
	if (a.val == b.val) return a.vis > b.vis;
	return a.val < b.val;
}

int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i) use[i] = i + 1;
	for (int i = 1; i <= m; ++i)
	{
		scanf("%d %d", &g[i].val, &g[i].vis);
		g[i].num = i;
	}
	sort(g + 1, g + 1 + m, cmp);
	int cnt = 1;
	int flag = 1;
	for (int i = 1; i <= m; ++i)
	{
		if (g[i].vis == 1)
		{
			g[i].u = 1;
			g[i].v = ++cnt;
		}
		else
		{
			int flag1 = 0;
			for (int j = 2; j <= cnt; ++j)
			{
				if (use[j] <= cnt) {
					g[i].u = j;
					g[i].v = use[j];
					use[j]++;
					flag1 = 1;
					break;
				}
			}
			if (!flag1) {
				flag = 0;
				break;
			}

		}
	}
	if (!flag)
		printf("-1\n");
	else
	{
		sort(g + 1, g + 1 + m, cmp1);
		for (int i = 1; i <= m; ++i)
		{
			printf("%d %d\n", g[i].u, g[i].v);
		}
	}
}


#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define ss second
#define ff first
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,A,B) for(int i=A;i<=B;i++)
#define mod 998244353
#define MOD (1000*1000*1000+7)
#define vid vector<double>
#define v1d vector<int>
#define v2d vector<vector<int>>
#define vip vector<pair<int,int> >
#define v1s vector<string>
#define v2s vector<vector<string> >
#define vsp vector<pair<string,string> >
#define pa pair<int,int>
#define print(v) for(auto i:v)cout<<i<<" ";cout<<"\n";
#define endl '\n'
#define input(b,n) for(int i=0;i<n;i++)cin>>b[i];
#define all(v) v.begin(),v.end()
#define Sort(v) sort(v.begin(),v.end())
#define RSort(v)   sort(v.rbegin(),v.rend())
int gcd(int a,int b){return b?gcd(b,a%b):a;}
//string s= bitset<64>(a).to_string();

int32_t main(){
    IOS
    int n,m;cin>>n>>m;
    vip w1,w0;
    v1d t(n+1);
    for(int i=1;i<=m;i++){
        int a,b;cin>>a>>b;
        if(b)w1.pb({a,i});
        else w0.pb({a,i});
    }
    Sort(w1);
    Sort(w0);
    v2d v;
    vip ans(m+1);

    //for(auto i:w0)cout<<i.ff<<" "<<i.ss<<"\n";

    for(int i=0;i<w1.size();i++){
        ans[w1[i].ss]= {1,i+2};
        t[i+2]= w1[i].ff;
    }

    //print(t);for(auto i:ans)cout<<i.ff<<" "<<i.ss<<"\n";

    set<pa> s;
    for(auto i:w0)s.insert(i);

    int x= 2,y= 1;
    while(!s.empty()){
        bool flag =true;
        int m= max(t[x],t[x+y]);
        if(s.end()==s.lower_bound({m,INT_MIN})){
            x++;
            if(x+y>n){
                y++;x= 2;
                if(x+y>n)break;
            }
            continue;
        }
        auto p= s.lower_bound({m,INT_MIN});
        pa i= *p;
        //cout<<i.ff<<" "<<i.ss<<" "<<x<<" "<<y<<"\n";
        if(flag&&(t[x]>i.ff||t[x+y]>i.ff)){
            cout<<"-1";return 0;
        }
        s.erase(p);

        ans[i.ss]= {x,x+y};
        x++;
        if(x+y>n){
            y++;
            x= 2;
            if(x+y>n)break;
        }
    }

    if(!s.empty()){
        cout<<"-1";
    }
    else
    for(int i=1;i<=m;i++)
        cout<<ans[i].ff<<" "<<ans[i].ss<<"\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define loop(i,b,e) for(int i=b;i<=e;i++)
#define loop2(i,e,b) for(int i=e;i>=b;i--)
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define X real()
#define Y imag()
#define cp(a,b)    ( (conj(a)*(b)).imag() )
#define length(a) (hypot((a).imag(), (a).real()))
typedef complex<double> point;
typedef long long ll;
typedef unsigned long long ull;
double PI = 3.141592653589793;
const double EPS = 1e-9;
const int N = 1e6 + 5;
const ll mod = 1e9 + 7;
const int oo = 1e9;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

int n, m;
vector<pair<int, pair<int, int>> > e;
pair<int, int> ans[N];

int main() {
	scanf("%d%d", &n, &m);
	loop(i, 1, m) {
		int a, b;
		scanf("%d%d", &a, &b);
		e.push_back({ a,{i,b} });
	}
	sort(e.begin(), e.end());
	priority_queue<pair<int, pair<int, int>> > q;
	int total = 0, curr = 1;
	loop(i, 0, m - 1) {
		if (e[i].second.second) {
			curr++;
			int cnt = 2;
			for (int j = 0; j < i && total < m; j++)
				if (e[j].second.second) {
					q.push({ -(e[j].first) , {curr,cnt} });
					cnt++;
					total++;
				}
			ans[e[i].second.first] = make_pair(1, curr);
		}
		else {
			if (!q.size()) {
				printf("-1");
				return 0;
			}
			int c = -q.top().first;
			if (c > e[i].first) {
				printf("-1");
				return 0;
			}
			ans[e[i].second.first] = make_pair(q.top().second.first, q.top().second.second);
			q.pop();
		}
	}
	loop(i, 1, m)
		printf("%d %d\n", ans[i].first, ans[i].second);
}


#include <bits/stdc++.h>
using namespace std;
#define loop(i,b,e) for(int i=b;i<=e;i++)
#define loop2(i,e,b) for(int i=e;i>=b;i--)
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define X real()
#define Y imag()
#define cp(a,b)    ( (conj(a)*(b)).imag() )
#define length(a) (hypot((a).imag(), (a).real()))
typedef complex<double> point;
typedef long long ll;
typedef unsigned long long ull;
double PI = 3.141592653589793;
const double EPS = 1e-9;
const int N = 1e6 + 5;
const ll mod = 1e9 + 7;
const int oo = 1e9;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

int n, m;
vector<pair<int,int> > e1, e2;
// 17
//20
// 28
pair<int, int> ans[N];

bool compare(pair<int,int> i,pair<int,int> j) {
	return i.first > j.first;
}

int main() {
	scanf("%d%d",&n,&m);
	loop(i, 1, m) {
		int a, b;
		scanf("%d%d",&a,&b);
		if (b) e1.push_back({ a,i });
		else e2.push_back({ a,i });
	}
	sort(e1.begin(), e1.end());
	sort(e2.begin(), e2.end());
	int cnt = 1;
	for (int i = 0; i < e1.size(); i++) {
		if (i > 0) e1[i].first += e1[i - 1].first;
		ans[e1[i].second] = make_pair(cnt, cnt + 1);
		cnt++;
	}
	int curr = 0;
	for (int i = 0; i < e1.size() && curr < e2.size(); i++) {
		int r = i + 1;
		while (curr < e2.size() && r < e1.size() && e1[r].first - (i > 0 ? e1[i - 1].first : 0) <= e2[curr].first) {
			ans[e2[curr].second] = make_pair(i + 1, r + 2);
			r++;
			curr++;
		}
	}
	if (curr < e2.size()) {
		printf("-1");
		return 0;
	}
	loop(i, 1, m)
		printf("%d %d\n",ans[i].first,ans[i].second);
}


#include <bits/stdc++.h>
using namespace std;
#define loop(i,b,e) for(int i=b;i<=e;i++)
#define loop2(i,e,b) for(int i=e;i>=b;i--)
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define X real()
#define Y imag()
#define cp(a,b)    ( (conj(a)*(b)).imag() )
#define length(a) (hypot((a).imag(), (a).real()))
typedef complex<double> point;
typedef long long ll;
typedef unsigned long long ull;
double PI = 3.141592653589793;
const double EPS = 1e-9;
const int N = 1e6 + 5;
const ll mod = 1e9 + 7;
const int oo = 1e9;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

int n, m;
vector<pair<int, pair<int, int>> > e;
pair<int, int> ans[N];

bool compare(pair<int, pair<int, int> > i, pair<int, pair<int, int> > j) {
	if (i.first == j.first) return i.second.second > j.second.second;
	return i.first > j.first;
}

int main() {
	scanf("%d%d", &n, &m);
	loop(i, 1, m) {
		int a, b;
		scanf("%d%d", &a, &b);
		e.push_back({ a,{i,b} });
	}
	sort(e.begin(), e.end(), compare);
	priority_queue<pair<int, pair<int, int>> > q;
	int total = 0, curr = 1;
	loop(i, 0, m - 1) {
		if (e[i].second.second) {
			curr++;
			int cnt = 2;
			for (int j = 0; j < i && total < m; j++)
				if (e[j].second.second) {
					q.push({ -(e[j].first) , {curr,cnt} });
					cnt++;
					total++;
				}
			ans[e[i].second.first] = make_pair(1, curr);
		}
		else {
			if (!q.size()) {
				printf("-1");
				return 0;
			}
			int c = -q.top().first;
			if (c > e[i].first) {
				printf("-1");
				return 0;
			}
			ans[e[i].second.first] = make_pair(q.top().second.first, q.top().second.second);
			q.pop();
		}
	}
	loop(i, 1, m)
		printf("%d %d\n", ans[i].first, ans[i].second);
}


#include <bits/stdc++.h>
using namespace std;
#define loop(i,b,e) for(int i=b;i<=e;i++)
#define loop2(i,e,b) for(int i=e;i>=b;i--)
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define X real()
#define Y imag()
#define cp(a,b)    ( (conj(a)*(b)).imag() )
#define length(a) (hypot((a).imag(), (a).real()))
typedef complex<double> point;
typedef long long ll;
typedef unsigned long long ull;
double PI = 3.141592653589793;
const double EPS = 1e-9;
const int N = 1e6 + 5;
const ll mod = 1e9 + 7;
const int oo = 1e9;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

int n, m;
vector<pair<int, pair<int, int>> > e;
pair<int, int> ans[N];

int main() {
	scanf("%d%d", &n, &m);
	loop(i, 1, m) {
		int a, b;
		scanf("%d%d", &a, &b);
		e.push_back({ a,{i,b} });
	}
	sort(e.begin(), e.end());
	priority_queue<pair<int, pair<int, int>> > q;
	int total = 0, curr = 1;
	loop(i, 0, m - 1) {
		if (e[i].second.second) {
			curr++;
			int cnt = 2;
			for (int j = 0; j < i && total < m; j++)
				if (e[j].second.second) {
					q.push({ -(e[i].first + e[j].first) , {curr,cnt} });
					cnt++;
					total++;
				}
			ans[e[i].second.first] = make_pair(1, curr);
			q.push({ -(e[i].first) , {curr,cnt} });
		}
		else {
			if (!q.size()) {
				printf("-1");
				return 0;
			}
			int c = -q.top().first;
			if (c > e[i].first) {
				printf("-1");
				return 0;
			}
			ans[e[i].second.first] = make_pair(q.top().second.first, q.top().second.second);
			q.pop();
		}
	}
	loop(i, 1, m)
		printf("%d %d\n", ans[i].first, ans[i].second);
}


#include <bits/stdc++.h>
using namespace std;
#define loop(i,b,e) for(int i=b;i<=e;i++)
#define loop2(i,e,b) for(int i=e;i>=b;i--)
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define X real()
#define Y imag()
#define cp(a,b)    ( (conj(a)*(b)).imag() )
#define length(a) (hypot((a).imag(), (a).real()))
typedef complex<double> point;
typedef long long ll;
typedef unsigned long long ull;
double PI = 3.141592653589793;
const double EPS = 1e-9;
const int N = 1e6 + 5;
const ll mod = 1e9 + 7;
const int oo = 1e9;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

int n, m;
vector<pair<int, pair<int, int>> > e;
pair<int, int> ans[N];

bool compare(pair<int, pair<int, int> > i, pair<int, pair<int, int> > j) {
	if (i.first == j.first) return i.second.second > j.second.second;
	return i.first < j.first;
}

int main() {
	scanf("%d%d", &n, &m);
	loop(i, 1, m) {
		int a, b;
		scanf("%d%d", &a, &b);
		e.push_back({ a,{i,b} });
	}
	sort(e.begin(), e.end(), compare);
	priority_queue<pair<int, pair<int, int>> > q;
	int total = 0, curr = 1;
	loop(i, 0, m - 1) {
		if (e[i].second.second) {
			curr++;
			int cnt = 2;
			for (int j = 0; j < i && total < m; j++)
				if (e[j].second.second) {
					q.push({ -(e[j].first) , {curr,cnt} });
					cnt++;
					total++;
				}
			ans[e[i].second.first] = make_pair(1, curr);
		}
		else {
			if (!q.size()) {
				printf("-1");
				return 0;
			}
			int c = -q.top().first;
			if (c > e[i].first) {
				printf("-1");
				return 0;
			}
			ans[e[i].second.first] = make_pair(q.top().second.first, q.top().second.second);
			q.pop();
		}
	}
	loop(i, 1, m)
		printf("%d %d\n", ans[i].first, ans[i].second);
}


#define mm(a) memset(a,0,sizeof(a));
#define max(x,y) (x)>(y)?(x):(y)
#define min(x,y) (x)<(y)?(x):(y)
#define Fopen freopen("1.in","r",stdin); freopen("m.out","w",stdout);
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,b,a) for(int i=(b);i>=(a);i--)
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int INF=0x3f3f3f3f;
const int MAXN = 2e5+5;

int x,n,m,cnta,cntb,w[MAXN];
struct node {
    int val,id;
} a[MAXN],b[MAXN];
struct tree {
    int x,y;
}ans[MAXN];

bool cmp(node a,node b) {
    return a.val<b.val;
}
int main() {
    scanf("%d%d",&n,&m);
    for(int i=1; i<=m; i++) {
        int val,is;
        scanf("%d%d",&val,&is);
        if(is==1) {
            cnta++;
            a[cnta].val=val;
            a[cnta].id=i;
        } else {
            cntb++;
            b[cntb].val=val;
            b[cntb].id=i;
        }
    }
    sort(a+1,a+1+cnta,cmp);
    sort(b+1,b+1+cntb,cmp);
    int now=1;
    for(int i=1;i<=cnta;i++){
        w[now]=a[i].val;
        ans[a[i].id].x=1;
        ans[a[i].id].y=++now;
    }
    int pos=n;
    now=2;
    for(int i=1;i<=cntb;i++){
        if(w[pos]>b[i].val){
            printf("-1\n");
            return 0;
        }
        ans[b[i].id].x=pos;
        ans[b[i].id].y=now;
        now++;
        if(now==pos)pos--,now=2;
    }
    for(int i=1;i<=m;i++)printf("%d %d\n",ans[i].x,ans[i].y);
    return 0;
}