#include <bits/stdc++.h>
typedef struct __ITEM {
  int wt;
  int ind;
  int typ;
} ITEM;
int cmpfunc(const void *, const void *);
int main() {
  int n, m, ans[100005][2], i, j, x, y;
  ITEM ar[100005];
  scanf("%d %d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d %d", &x, &y);
    ar[i].wt = x;
    ar[i].typ = y;
    ar[i].ind = i;
  }
  qsort(ar, m, sizeof(ITEM), cmpfunc);
  x = 0;
  y = 2;
  for (i = 0, j = 0; i < m; i++) {
    if (ar[i].typ) {
      ans[ar[i].ind][0] = j;
      ans[ar[i].ind][1] = ++j;
    } else {
      if (y > j) break;
      ans[ar[i].ind][0] = x++;
      ans[ar[i].ind][1] = y;
      if (y - x == 1) {
        x = 0;
        y++;
      }
    }
  }
  if (i < m)
    printf("-1\n");
  else {
    for (i = 0; i < m; i++) printf("%d %d\n", ans[i][0] + 1, ans[i][1] + 1);
  }
  return 0;
}
int cmpfunc(const void *a, const void *b) {
  int wta, wtb;
  wta = ((ITEM *)a)->wt;
  wtb = ((ITEM *)b)->wt;
  if (wta != wtb)
    return wta - wtb;
  else {
    return ((ITEM *)b)->typ - ((ITEM *)a)->typ;
  }
}
