#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int maxm = 200005;
int n, m;
struct p {
  int w, k, num, l, r;
} a[maxn];
bool cmp1(p a, p b) {
  if (a.w == b.w) return a.k > b.k;
  return a.w < b.w;
}
bool cmp2(p a, p b) { return a.num < b.num; }
int main() {
  int f[maxn] = {0};
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a[i].w, &a[i].k);
    a[i].num = i;
  }
  sort(a, a + m, cmp1);
  int cot = 1, sum = 3, y = 3;
  a[0].l = 1;
  a[0].r = 2;
  a[1].l = 2;
  a[1].r = 3;
  int x = 3, t;
  for (int i = 1; i < maxn; i++) {
    f[i] = i + 2;
  }
  if (n == 2 && a[0].k == 1) {
    printf("1 2\n");
    return 0;
  } else if (a[0].k != 1 || a[1].k != 1) {
    printf("-1\n");
    return 0;
  } else {
    for (int i = 2; i < m; i++) {
      if (a[i].k == 0 && cot >= 1) {
        cot--;
        for (t = 1; t < maxn; t++)
          if (f[t] <= x) break;
        a[i].l = t;
        a[i].r = f[t]++;
      } else if (a[i].k == 0) {
        printf("-1\n");
        return 0;
      } else {
        a[i].l = x;
        a[i].r = ++x;
        cot += sum - 1;
        sum++;
      }
    }
  }
  sort(a, a + m, cmp2);
  for (int i = 0; i < m; i++) {
    printf("%d %d\n", a[i].l, a[i].r);
  }
  return 0;
}
