#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, m, flag;
struct Edge {
  int id, w, c, x, y;
} e[100005];
bool cmp1(Edge a, Edge b) { return a.w == b.w ? a.c > b.c : a.w < b.w; }
bool cmp2(Edge a, Edge b) { return a.id < b.id; }
int main() {
  int i, k, a, b;
  while (~scanf("%d %d", &n, &m)) {
    for (i = 0; i < m; i++) {
      scanf("%d %d", &a, &b);
      e[i].id = i;
      e[i].w = a;
      e[i].c = b;
    }
    sort(e, e + m, cmp1);
    k = flag = 1;
    int l = 1, r = 3;
    for (i = 0; i < m; i++) {
      if (e[i].c) {
        e[i].x = 1;
        e[i].y = ++k;
      } else {
        if (l < r - 1)
          l++;
        else
          r++, l = 2;
        if (r > k) {
          flag = 0;
          break;
        }
        e[i].x = l;
        e[i].y = r;
      }
    }
    if (flag) {
      sort(e, e + m, cmp2);
      for (i = 0; i < m; i++) printf("%d %d\n", e[i].x, e[i].y);
    } else
      printf("-1\n");
  }
  return 0;
}
