#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, inf = 0x3f3f3f3f;
int n, m, now;
struct E {
  int c, f, i;
  bool operator<(const E& b) const { return c != b.c ? c < b.c : f > b.f; }
} e[N];
struct D {
  int x, y;
  bool operator<(const D& b) const { return x != b.x ? x < b.x : y < b.y; }
  bool operator==(const D& b) const { return x == b.x && y == b.y; }
} ans[N], b[N];
int hd, tl;
void link(int u, int v, int i) { ans[i] = {u, v}; }
bool solve() {
  for (int i = 1; i <= m; ++i) {
    if (e[i].f == 1) {
      link(1, now, e[i].i);
      for (int i = 2; i < now && tl < N - 1; ++i) b[++tl] = {i, now};
      now++;
    } else {
      if (hd > tl) return 0;
      link(b[hd].x, b[hd].y, e[i].i);
      hd++;
    }
  }
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) scanf("%d%d", &e[i].c, &e[i].f), e[i].i = i;
  sort(e + 1, e + 1 + m);
  hd = 1, tl = 0, now = 2;
  if (!solve())
    puts("-1");
  else
    for (int i = 1; i <= m; ++i) printf("%d %d\n", ans[i].x, ans[i].y);
  return 0;
}
