#include <bits/stdc++.h>
using namespace std;
int x[100000], y[100000];
int nxt[100000];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<pair<pair<int, int>, int> > V;
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    V.push_back(pair<pair<int, int>, int>(pair<int, int>(a, !b), i));
  }
  sort(V.begin(), V.end());
  for (int i = 1; i < n; i++) {
    nxt[i] = i + 1;
  }
  int size = 1, rem = 0, k = 1;
  bool OK = 1;
  for (int i = 0; i < V.size(); i++) {
    if (V[i].first.second == 0) {
      rem += size - 1;
      x[V[i].second] = 0;
      y[V[i].second] = size;
      size++;
      k = 1;
    } else {
      if (rem == 0) {
        OK = 0;
        break;
      }
      while (nxt[k] > size - 1) k++;
      x[V[i].second] = k;
      y[V[i].second] = nxt[k];
      nxt[k]++;
      rem--;
    }
  }
  if (!OK) {
    printf("-1\n");
    return 0;
  }
  for (int i = 0; i < m; i++) {
    printf("%d %d\n", x[i] + 1, y[i] + 1);
  }
}
