#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long mod2 = 1e9 + 9;
double eps = 1e-9;
const int MAX_SIZE = 1 << 19;
int n, m, t;
struct Edge {
  int value;
  int isSpanEdge;
  int index;
  int s;
  int e;
  Edge(int _value, int _isSpanEdge, int _index)
      : value(_value), isSpanEdge(_isSpanEdge), index(_index), s(0), e(0) {}
  Edge() {}
  bool operator<(const Edge &o) const {
    if (o.value == value) {
      return isSpanEdge > o.isSpanEdge;
    }
    return value < o.value;
  }
};
void insertSpan(Edge &e, int &currVertex) {
  e.s = currVertex++;
  e.e = 1;
}
void insertNotSpan(Edge &e, int &currVertex, int &nextNeighbour) {
  e.s = currVertex;
  e.e = nextNeighbour++;
  if (currVertex == nextNeighbour) {
    currVertex++;
    nextNeighbour = 2;
  }
}
bool check(const int currSpanVertex, const int currNotSpanVertex) {
  return !(currSpanVertex == currNotSpanVertex);
}
vector<Edge> edges;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int value, isSpanEdge;
    cin >> value >> isSpanEdge;
    edges.push_back(Edge(value, isSpanEdge, i));
  }
  if (m == 1) {
    cout << 1 << " " << 2 << '\n';
    return 0;
  }
  sort(edges.begin(), edges.end());
  if (!edges[0].isSpanEdge || !edges[1].isSpanEdge) {
    cout << -1 << '\n';
    return 0;
  }
  int currSpanVertex = 2;
  int currNotSpanVertex = 3;
  int currNotSpanVertexNeighbour = 2;
  insertSpan(edges[0], currSpanVertex);
  insertSpan(edges[1], currSpanVertex);
  for (int i = 2; i < m; ++i) {
    Edge &e = edges[i];
    if (!e.isSpanEdge && !check(currSpanVertex, currNotSpanVertex)) {
      cout << -1 << '\n';
      return 0;
    }
    e.isSpanEdge
        ? insertSpan(e, currSpanVertex)
        : insertNotSpan(e, currNotSpanVertex, currNotSpanVertexNeighbour);
  }
  sort(edges.begin(), edges.end(),
       [](const Edge &e1, const Edge &e2) { return e1.index < e2.index; });
  for (const auto &e : edges) {
    cout << e.s << " " << e.e << '\n';
  }
}
