#include <bits/stdc++.h>
using namespace std;
int inc[100005], ansx[100005], ansy[100005];
pair<int, pair<int, int> > edg[100005];
int main() {
  int n, m, i, j, avl, bx, by, is, a, b, wt, ind, flag;
  while (cin >> n >> m) {
    for (i = 0; i < m; i++) {
      scanf("%d%d", &a, &b);
      edg[i] = make_pair(a, make_pair(b ^ 1, i));
      inc[i] = b;
    }
    sort(edg, edg + m);
    avl = 0;
    bx = 1;
    by = 3;
    flag = 1;
    for (i = 0, j = 1; i < m; i++) {
      wt = edg[i].first;
      is = edg[i].second.first ^ 1;
      ind = edg[i].second.second;
      if (is) {
        ansx[ind] = j;
        ansy[ind] = j + 1;
        avl += j - 1;
        j++;
      } else {
        if (!avl) {
          flag = 0;
          break;
        }
        avl--;
        ansx[ind] = bx;
        ansy[ind] = by;
        bx++;
        if (bx + 1 == by) {
          bx = 1;
          by++;
        }
      }
    }
    if (!flag)
      puts("-1");
    else {
      for (i = 0; i < m; i++) {
        printf("%d %d\n", ansx[i], ansy[i]);
      }
    }
  }
}
