#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int N = 1e5 + 5;
struct edge {
  bool operator<(const edge& e) const { return w < e.w; }
  int order, u, v, w, st;
};
int x[N];
edge e[N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (m); ++i) {
    e[i].order = i;
    scanf("%d%d", &e[i].w, &e[i].st);
  }
  sort(e, e + m);
  int u, v = 1;
  for (int i = (0); i < (m); ++i) {
    if (!e[i].st) continue;
    e[i].u = v;
    e[i].v = v + 1;
    x[v] = e[i].w;
    ++v;
  }
  u = 1, v = u + 2;
  for (int i = (0); i < (m); ++i) {
    if (e[i].st) continue;
    if (x[v - 1] > e[i].w) {
      puts("-1");
      return 0;
    }
    e[i].u = u;
    e[i].v = v;
    if (++u == v - 1) {
      u = 1;
      ++v;
    }
  }
  sort(e, e + m,
       [](const edge& e1, const edge& e2) { return e1.order < e2.order; });
  for (int i = (0); i < (m); ++i) {
    printf("%d %d\n", e[i].u, e[i].v);
  }
  return 0;
}
