#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
struct edge {
  int peso, mst, id;
  edge(int peso, int mst, int id) : peso(peso), mst(mst), id(id) {}
  edge() {}
};
edge arestas[100010];
int nex[100010];
pair<int, int> nodes[100010];
bool cmp(edge a, edge b) {
  if (a.peso == b.peso) {
    return a.mst > b.mst;
  }
  return a.peso < b.peso;
}
int main(void) {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> x >> y;
    arestas[i] = edge(x, y, i);
  }
  sort(arestas, arestas + m, cmp);
  for (int i = 3; i <= n; ++i) nex[i] = i - 2;
  int curr = 2;
  int pre = 1;
  if (arestas[0].mst) {
    nodes[arestas[0].id] = make_pair(1, 2);
  } else {
    cout << -1 << "\n";
    return 0;
  }
  for (int i = 1; i < m; ++i) {
    if (arestas[i].mst) {
      if (curr + 1 <= n) {
        nodes[arestas[i].id] = make_pair(curr, curr + 1);
        curr++;
      } else {
        cout << -1 << "\n";
        return 0;
      }
    } else {
      while (pre <= curr && nex[pre] <= 0) {
        pre++;
      }
      if (pre == curr + 1) {
        cout << -1 << "\n";
        return 0;
      }
      nodes[arestas[i].id] = make_pair(pre, nex[pre]);
      nex[pre]--;
    }
  }
  if (curr < n) {
    cout << -1 << "\n";
    return 0;
  }
  for (int i = 0; i < m; ++i) {
    cout << nodes[i].first << " " << nodes[i].second << "\n";
  }
  return 0;
}
