#include <bits/stdc++.h>
using namespace std;
struct TEdge {
  int u, v, len, numb, mst;
};
struct Edge {
  int u, v;
};
TEdge E[100000 + 69];
vector<int> AddedNodes;
vector<Edge> UsslesEdges;
vector<int> NotConectedNodes;
int r(int x) { return rand() % x; }
int byVal(const void* va, const void* vb) {
  TEdge a = *(TEdge*)va;
  TEdge b = *(TEdge*)vb;
  if (a.len < b.len) return -1;
  if (a.len > b.len) return 1;
  if (a.mst == b.mst) return 0;
  if (a.mst == 1) return -1;
  return 1;
}
int byNumb(const void* va, const void* vb) {
  TEdge a = *(TEdge*)va;
  TEdge b = *(TEdge*)vb;
  if (a.numb < b.numb) return -1;
  if (a.numb == b.numb) return 0;
  return 1;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> E[i].len >> E[i].mst;
    E[i].numb = i;
  }
  qsort(E, m, sizeof(TEdge), byVal);
  for (int i = 2; i <= n; i++) NotConectedNodes.push_back(i);
  int addedUssles = 0;
  for (int i = 0; i < m; i++) {
    if (E[i].mst == 0 || NotConectedNodes.size() == 0) {
      if (UsslesEdges.size() == 0) {
        cout << -1 << endl;
        return 0;
      } else {
        E[i].u = UsslesEdges[UsslesEdges.size() - 1].u;
        E[i].v = UsslesEdges[UsslesEdges.size() - 1].v;
        UsslesEdges.pop_back();
      }
    } else {
      E[i].u = 1;
      int next = NotConectedNodes[NotConectedNodes.size() - 1];
      NotConectedNodes.pop_back();
      E[i].v = next;
      if (addedUssles < m) {
        for (int j = 0; j < AddedNodes.size(); j++) {
          Edge temp;
          temp.u = next;
          temp.v = AddedNodes[j];
          UsslesEdges.push_back(temp);
          addedUssles++;
        }
        AddedNodes.push_back(next);
      }
    }
  }
  qsort(E, m, sizeof(TEdge), byNumb);
  for (int i = 0; i < m; i++) cout << E[i].u << " " << E[i].v << endl;
  return 0;
}
