#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using Pii = pair<int, int>;
constexpr int MAX = 200010;
struct Edge {
  int w, id;
  bool operator<(const Edge& e) const { return w == e.w ? id < e.id : w < e.w; }
} p[MAX], q[MAX];
int a[MAX], b[MAX], x[MAX], up[MAX], u[MAX], v[MAX], pre[MAX], nxt[MAX];
bool Solve(int n, int m) {
  int pc = 0, qc = 0;
  for (int i = 0; i < m; ++i) {
    if (b[i])
      p[pc++] = {a[i], i};
    else
      q[qc++] = {a[i], i};
  }
  sort(p, p + pc);
  sort(q, q + qc);
  x[0] = 0;
  for (int i = 1; i < n; ++i) {
    x[i] = p[i - 1].w;
    u[p[i - 1].id] = i - 1;
    v[p[i - 1].id] = i;
  }
  for (int i = 1; i < n; ++i) {
    up[i] = i - 2;
    pre[i] = i - 1;
    nxt[i] = i + 1;
  }
  for (int i = 0; i < qc; ++i) {
    int it = upper_bound(x + 1, x + n, q[i].w) - x - 1;
    if (it < 2) return false;
    while (up[it] < 0) it = pre[it];
    if (it < 2) return false;
    u[q[i].id] = up[it];
    v[q[i].id] = it;
    if ((--up[it]) < 0) {
      pre[nxt[it]] = pre[it];
      nxt[pre[it]] = nxt[it];
    }
  }
  return true;
}
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 0; i < m; ++i) {
      scanf("%d%d", &a[i], &b[i]);
    }
    if (!Solve(n, m)) {
      printf("-1\n");
    } else {
      for (int i = 0; i < m; ++i) {
        printf("%d %d\n", u[i] + 1, v[i] + 1);
      }
    }
  }
  return 0;
}
