#include <bits/stdc++.h>
using namespace std;
const int SIGMA_SIZE = 26;
const int MAXNODE = 111000;
const int MAXS = 150 + 10;
int n, m;
struct node {
  int u, v, o;
  bool operator<(const node &b) const {
    if (u == b.u) return v > b.v;
    return u < b.u;
  }
} a[100010];
int b[100010];
int c[100010];
int fun() {
  int e = 1, x = 1, y = 3;
  for (int i = 1; i <= m; i++) {
    if (a[i].v) {
      b[a[i].o] = e;
      c[a[i].o] = ++e;
    } else {
      if (y > e) return 0;
      b[a[i].o] = x;
      c[a[i].o] = y;
      if (--x == 0) {
        y += 1;
        x = y - 2;
      }
    }
  }
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a[i].u, &a[i].v);
    a[i].o = i;
  }
  sort(a + 1, a + 1 + m);
  if (fun()) {
    for (int i = 1; i <= m; i++) {
      cout << b[i] << " " << c[i] << endl;
    }
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
