#include <bits/stdc++.h>
using namespace std;
int n, m;
const int MAXN = 100005;
struct Node {
  int w, ty, x, y, id;
} f[MAXN];
bool cmp1(Node a, Node b) {
  if (a.w != b.w) return a.w < b.w;
  return a.ty > b.ty;
}
bool cmp2(Node a, Node b) { return a.id < b.id; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &f[i].w, &f[i].ty);
    f[i].id = i;
  }
  sort(f + 1, f + m + 1, cmp1);
  long long dq, now;
  dq = 0;
  now = 0;
  bool flag = true;
  for (int i = 1; i <= m; ++i) {
    if (!flag) break;
    if (f[i].ty == 1) {
      if (now == 0) {
        f[i].x = 1;
        f[i].y = 2;
        dq = 0;
        now = 2;
      } else {
        f[i].x = now;
        f[i].y = now + 1;
        dq += now - 1;
        now++;
      }
    } else {
      if (dq == 0) {
        flag = false;
        break;
      } else
        dq--;
    }
  }
  if (!flag) {
    printf("-1\n");
    return 0;
  }
  int dq1, dq2;
  dq1 = 3;
  dq2 = 1;
  for (int i = 1; i <= m; ++i) {
    if (f[i].ty == 0) {
      f[i].x = dq1;
      f[i].y = dq2;
      dq2--;
      if (dq2 == 0) {
        dq1++;
        dq2 = dq1 - 2;
      }
    }
  }
  sort(f + 1, f + m + 1, cmp2);
  for (int i = 1; i <= m; ++i) printf("%d %d\n", f[i].x, f[i].y);
  return 0;
}
