#include <bits/stdc++.h>
using namespace std;
int n, m;
int vis[100000 + 10];
struct NODE {
  int cost, flag, ord, from, to;
} node[100000 + 10];
bool cmp(NODE a, NODE b) {
  if (a.cost == b.cost) return a.flag > b.flag;
  return a.cost < b.cost;
}
bool cmp1(NODE a, NODE b) { return a.ord < b.ord; }
int main() {
  int from, to;
  bool sign;
  while (scanf("%d %d", &n, &m) != EOF) {
    sign = true;
    for (int i = 1; i <= n; i++) vis[i] = i + 2;
    for (int i = 0; i < m; i++) {
      scanf("%d %d", &node[i].cost, &node[i].flag);
      node[i].ord = i;
    }
    sort(node, node + m, cmp);
    from = 1;
    to = 2;
    for (int i = 0; i < m; i++) {
      if (node[i].flag) {
        node[i].from = from;
        node[i].to = to;
        from++;
        to++;
      } else {
        bool flag = false;
        for (int j = 1; j <= from - 1; j++) {
          if (vis[j] <= from) {
            flag = true;
            node[i].from = j;
            node[i].to = vis[j];
            vis[j]++;
            break;
          }
        }
        if (!flag) {
          sign = false;
          break;
        }
      }
    }
    if (!sign)
      printf("-1\n");
    else {
      sort(node, node + m, cmp1);
      for (int i = 0; i < m; i++) printf("%d %d\n", node[i].from, node[i].to);
    }
  }
  return 0;
}
