#include <bits/stdc++.h>
using namespace std;
const int mm = 100006;
struct P {
  int x, y, id;
  P() {}
  P(int _x, int _y, int _id) {
    x = _x;
    y = _y;
    id = _id;
  }
  P(int _x, int _y) {
    x = _x;
    y = _y;
  }
} ans[mm];
int cmp(P a, P b) {
  if (a.x != b.x) return a.x < b.x;
  return a.y > b.y;
}
vector<P> g;
int n, m;
int f[mm];
int ba(int k) {
  if (f[k] != k) f[k] = ba(f[k]);
  return f[k];
}
void insert(int x, int y) {
  x = ba(x);
  y = ba(y);
  f[x] = y;
}
int cura, curb, curn;
int next() {
  if (cura + 1 < curb - 1) {
    ++cura;
    return 0;
  } else {
    if (curb + 1 > curn) return -1;
    ++curb;
    cura = 1;
    if (cura >= curb - 1) return -1;
    return 0;
  }
  return 0;
}
int main() {
  int x, y;
  while (cin >> n >> m) {
    g.clear();
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &x, &y);
      g.push_back(P(x, y, i));
    }
    sort(g.begin(), g.end(), cmp);
    cura = 1;
    curb = 2;
    curn = 1;
    int imp = 0;
    for (int i = 0; imp == 0 && i < m; i++) {
      if (g[i].y == 0) {
        if (next() >= 0) {
          ans[g[i].id] = P(cura, curb);
        } else
          imp = 1;
      } else {
        ans[g[i].id] = P(curn, curn + 1);
        curn++;
      }
    }
    if (imp) {
      printf("-1\n");
    } else {
      for (int i = 0; i < m; i++) printf("%d %d\n", ans[i].x, ans[i].y);
    }
  }
  return 0;
}
