#include <bits/stdc++.h>
using namespace std;
struct node {
  int w, p, id;
  node() {}
  node(int _w, int _p, int _id) { w = _w, p = _p, id = _id; }
  bool operator<(const node other) const {
    if (w == other.w) return p > other.p;
    return w < other.w;
  }
};
int n, m;
node v[112345];
node v2[112345];
pair<int, int> res[112345];
int last[112345];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    v[i] = node(x, y, i);
    v2[i] = v[i];
  }
  sort(v2, v2 + m);
  bool flag = true;
  int cnt = 1;
  int h1 = 2, h2 = 3;
  for (int i = 2; i < 112345; i++) {
    last[i] = i;
  }
  for (int i = 0; i < m; i++) {
    if (v2[i].p == 1) {
      res[v2[i].id] = make_pair(1, ++cnt);
      h1 = 2;
      h2 = last[2] + 1;
    } else {
      if (h2 > cnt) {
        h1++;
        h2 = last[h1] + 1;
      }
      last[h1] = h2;
      if (h2 > cnt || h1 > cnt)
        flag = false;
      else
        res[v2[i].id] = make_pair(h1, h2);
      h2++;
    }
  }
  if (!flag) {
    puts("-1");
    return 0;
  }
  for (int i = 0; i < m; i++) {
    printf("%d %d\n", res[i].first, res[i].second);
  }
  return 0;
}
