#include <bits/stdc++.h>
using namespace std;
const int M = 1000100;
struct node {
  int w, flag;
  int a, b;
  int id;
  long long num;
} a[M];
int n, pos[M], m, s[M];
bool cmp(const node &x, const node &y) {
  if (x.w == y.w) return x.flag > y.flag;
  return x.w < y.w;
}
int fa[M];
bool cmp1(const node &x, const node &y) { return x.id < y.id; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a[i].w, &a[i].flag);
    a[i].id = i;
  }
  sort(a + 1, a + 1 + m, cmp);
  for (int i = 1; i <= n; i++) fa[i] = i;
  int k = 1;
  for (int i = 1; i <= m; i++)
    if (a[i].flag) {
      a[i].a = k;
      pos[k] = i;
      a[i].num = (long long)(k - 1) * k / 2 + 1;
      a[i].b = ++k;
    }
  bool flag = 0;
  for (int i = 1; i <= m; i++)
    if (a[i].flag)
      if (a[i].num < (long long)i) {
        flag = 1;
        break;
      }
  if (flag) {
    printf("-1\n");
    return 0;
  }
  pos[n] = m + 1;
  int h = 3, s1 = 1;
  for (int i = 1; i < n; i++) {
    for (int j = pos[i] + 1; j < pos[i + 1];) {
      a[j].a = s1;
      a[j].b = h;
      s1++;
      if (s1 == h - 1) {
        s1 = 1;
        h++;
      }
      j++;
    }
  }
  if (flag) {
    printf("-1\n");
    return 0;
  }
  sort(a + 1, a + 1 + m, cmp1);
  for (int i = 1; i <= m; i++) printf("%d %d\n", a[i].a, a[i].b);
  return 0;
}
