#include <bits/stdc++.h>
using namespace std;
const int maxN = 100000;
struct Node {
  int w, s, u, v;
};
int n, m;
Node node[maxN];
int p[maxN];
bool Cmp(const int& a, const int& b) {
  if (node[a].w != node[b].w) {
    return node[a].w < node[b].w;
  }
  return node[a].s > node[b].s;
}
bool Calc() {
  long tot = 0, num = 1;
  int u = 2, v = 3;
  for (int j = 0; j < m; j++) {
    if (!node[p[j]].s && tot - j <= 0) {
      return false;
    }
    if (node[p[j]].s) {
      num++;
      tot = num * (num - 1) / 2;
      node[p[j]].u = 1;
      node[p[j]].v = num;
    } else {
      node[p[j]].u = u;
      node[p[j]].v = v;
      u++;
      if (u == v) {
        v++;
        u = 2;
      }
    }
  }
  return true;
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int j = 0; j < m; j++) {
      scanf("%d%d", &node[j].w, &node[j].s);
      p[j] = j;
    }
    sort(p, p + m, Cmp);
    if (Calc()) {
      for (int j = 0; j < m; j++) {
        printf("%d %d\n", node[j].u, node[j].v);
      }
    } else {
      puts("-1");
    }
  }
  return 0;
}
