#include <bits/stdc++.h>
using namespace std;
int *a, *b;
bool cmp(int x, int y) {
  return (a[x] < a[y]) || (a[x] == a[y] && b[x] > b[y]);
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  a = (int *)malloc(m * sizeof(int));
  b = (int *)malloc(m * sizeof(int));
  for (int i = 0; i < m; i++) scanf("%d %d", a + i, b + i);
  int *idx = (int *)malloc(m * sizeof(int));
  for (int i = 0; i < m; i++) idx[i] = i;
  sort(idx, idx + m, cmp);
  int *ansu = (int *)malloc(m * sizeof(int));
  int *ansv = (int *)malloc(m * sizeof(int));
  int onu = 1, ofu = 1, ofv = 2;
  for (int i = 0; i < m; i++) {
    int idxi = idx[i];
    if (b[idxi]) {
      ansu[idxi] = onu;
      ansv[idxi] = n;
      onu++;
    } else {
      if (ofv >= onu) {
        printf("-1\n");
        return 0;
      }
      ansu[idxi] = ofu;
      ansv[idxi] = ofv;
      ofu++;
      if (ofu == ofv) {
        ofu = 1;
        ofv++;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    printf("%d %d\n", ansu[i], ansv[i]);
  }
  return 0;
}
