#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct mnode {
  int w, id;
} m1[N], m0[N];
int n1 = 0, n0 = 0, n, m, vw[N];
int ansu[N], ansv[N];
bool cmp(mnode A, mnode B) { return A.w < B.w; }
int main() {
  int w, t;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &w, &t);
    if (t == 0) {
      m0[++n0].w = w;
      m0[n0].id = i;
    } else {
      m1[++n1].w = w;
      m1[n1].id = i;
    }
  }
  if (n1 != n - 1) {
    printf("-1\n");
    return 0;
  }
  if (n == 2) {
    if (m > 1) printf("-1\n");
    printf("1 2\n");
    return 0;
  }
  sort(m1 + 1, m1 + n1 + 1, cmp);
  sort(m0 + 1, m0 + n0 + 1, cmp);
  for (int i = 1; i <= n1; i++) {
    ansu[m1[i].id] = 1;
    ansv[m1[i].id] = i + 1;
    vw[i + 1] = m1[i].w;
  }
  int k1 = 3, k2 = 2;
  bool changed = 0;
  for (int i = 1; i <= n0; i++) {
    changed = 0;
    while (k1 <= n && m0[i].w < vw[k1]) {
      changed = 1;
      k1++;
    }
    if (k1 > n) {
      printf("-1");
      return 0;
    }
    if (changed) k2 = 2;
    ansu[m0[i].id] = k1;
    ansv[m0[i].id] = k2;
    k2++;
    if (k2 == k1) {
      k1++;
      k2 = 2;
    }
  }
  for (int i = 1; i <= m; i++) printf("%d %d\n", ansu[i], ansv[i]);
  return 0;
}
