#include <bits/stdc++.h>
using namespace std;
class edge {
 public:
  bool in_tree;
  int weight;
  int index;
  edge(bool i, int w, int in) {
    in_tree = i;
    weight = w;
    index = in;
  }
};
int main() {
  int n;
  int m;
  cin >> n >> m;
  vector<edge *> inputs;
  vector<pair<int, int> > ans(m, {0, 0});
  for (int i = 0; i < m; i++) {
    int w;
    bool in;
    cin >> w >> in;
    inputs.push_back(new edge(in, w, i));
  }
  sort(inputs.begin(), inputs.end(), [&](edge *a, edge *b) {
    if (a->weight == b->weight)
      return a->in_tree > b->in_tree;
    else
      return a->weight < b->weight;
  });
  vector<pair<int, int> > connections(0);
  int idx = 0;
  int discovery = 0;
  for (int i = 0; i < m; i++) {
    edge *x = inputs[i];
    if (x->in_tree) {
      discovery++;
      connections.push_back({discovery - 2, discovery});
      ans[x->index] = {discovery - 1, discovery};
    } else {
      while (idx < connections.size() && connections[idx].first < 0) idx++;
      if (idx == connections.size()) {
        cout << -1 << endl;
        return 0;
      }
      ans[x->index] = connections[idx];
      connections[idx].first--;
    }
  }
  for (pair<int, int> x : ans)
    cout << x.first + 1 << " " << x.second + 1 << endl;
}
