#include <bits/stdc++.h>
using namespace std;
class Edge {
 public:
  int w;
  bool isSpanningTree;
  int a, b;
  int i;
  Edge(int _w, bool _isSpanningTree, int _i) {
    w = _w;
    isSpanningTree = _isSpanningTree;
    i = _i;
  }
};
int n, m;
vector<Edge> e;
queue<pair<int, int>> avaliableEdges;
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int ai, bi;
    cin >> ai >> bi;
    e.push_back(Edge(ai, bi == 1, i));
  }
  sort(e.begin(), e.end(), [](Edge &a, Edge &b) -> bool {
    return a.w < b.w || (a.w == b.w && a.isSpanningTree > b.isSpanningTree);
  });
  bool answerExists = true;
  int lastVertex = 1;
  for (auto &edge : e) {
    if (edge.isSpanningTree) {
      edge.a = 1;
      edge.b = ++lastVertex;
      if (lastVertex > n) {
        answerExists = false;
        break;
      }
      for (int i = 2; i < lastVertex; i++) {
        if (avaliableEdges.size() > m) break;
        avaliableEdges.emplace(i, lastVertex);
      }
    } else {
      if (avaliableEdges.empty()) {
        answerExists = false;
        break;
      }
      edge.a = avaliableEdges.front().first;
      edge.b = avaliableEdges.front().second;
      avaliableEdges.pop();
    }
  }
  if (answerExists) {
    sort(e.begin(), e.end(),
         [](Edge &a, Edge &b) -> bool { return a.i < b.i; });
    for (auto &edge : e) {
      printf("%d %d\n", edge.a, edge.b);
    }
  } else {
    printf("-1\n");
  }
  return 0;
}
