#include <bits/stdc++.h>
using namespace std;
vector<pair<int, pair<int, int> > > answ;
int n, m, i, j;
pair<pair<int, int>, int> a[200002];
int b, c;
int ka;
int h;
int az1, az2;
int qan;
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &a[i].first.first, &a[i].first.second);
    a[i].first.second *= -1;
    a[i].second = i;
  }
  sort(a + 1, a + m + 1);
  h = 1;
  az1 = 1;
  qan = 0;
  for (i = 1; i <= m; i++) {
    int f = a[i].second;
    b = a[i].first.first;
    c = a[i].first.second;
    if (c == 0) {
      if (ka == 0) {
        cout << -1 << endl;
        return 0;
      }
      ka--;
      if (az1 <= 2) {
        az1 = 3;
        qan = 0;
      }
      qan++;
      if (qan == az1 - 1) {
        az1++;
        qan = 1;
      }
      answ.push_back(make_pair(f, make_pair(az1, qan)));
    } else {
      h++;
      ka += h - 2;
      answ.push_back(make_pair(f, make_pair(h - 1, h)));
    }
  }
  sort(answ.begin(), answ.end());
  for (i = 0; i < answ.size(); i++) {
    printf("%d %d\n", answ[i].second.first, answ[i].second.second);
  }
  return 0;
}
