#include <bits/stdc++.h>
using namespace std;
double err = 0.0000001;
struct node {
  node(int cost, int ord, int type) {
    this->cost = cost;
    this->ord = ord;
    this->type = type;
  }
  int cost, ord, x, y, type;
};
int n, m;
vector<node> v;
bool comp1(node a, node b) {
  if (a.cost == b.cost) return a.type > b.type;
  return a.cost < b.cost;
}
bool comp2(node a, node b) { return a.ord < b.ord; }
vector<vector<int> > g;
int vst = 1;
int idx = -2;
int main() {
  cin >> n >> m;
  g.resize(n + 1);
  int c, t;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &c, &t);
    v.push_back(node(c, i, t));
  }
  sort(v.begin(), v.end(), comp1);
  for (int i = 0; i < m; i++) {
    if (v[i].type) {
      v[i].x = 1;
      v[i].y = ++vst;
      g[vst].push_back(vst);
      idx = 2;
    } else {
      if (idx > 0 && idx < vst && vst - idx >= g[idx].size()) {
        int temp = g[idx].size() - 1;
        g[idx].push_back(g[idx][temp] + 1);
        v[i].x = idx;
        v[i].y = g[idx][temp] + 1;
        if (vst - idx < g[idx].size()) idx++;
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  sort(v.begin(), v.end(), comp2);
  for (int i = 0; i < m; i++) printf("%d %d\n", v[i].x, v[i].y);
}
