#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 2e5 + 5;
int x, n, m, cnta, cntb, w[MAXN];
struct node {
  int val, id;
} a[MAXN], b[MAXN];
struct tree {
  int x, y;
} ans[MAXN];
bool cmp(node a, node b) { return a.val < b.val; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int val, is;
    scanf("%d%d", &val, &is);
    if (is == 1) {
      cnta++;
      a[cnta].val = val;
      a[cnta].id = i;
    } else {
      cntb++;
      b[cntb].val = val;
      b[cntb].id = i;
    }
  }
  sort(a + 1, a + 1 + cnta, cmp);
  sort(b + 1, b + 1 + cntb, cmp);
  int now = 1;
  for (int i = 1; i <= cnta; i++) {
    ans[a[i].id].x = 1;
    ans[a[i].id].y = ++now;
    w[now] = a[i].val;
  }
  int pos = 3;
  now = 2;
  for (int i = 1; i <= cntb; i++) {
    if (w[pos] > b[i].val) return printf("-1\n"), 0;
    ans[b[i].id].x = pos;
    ans[b[i].id].y = now;
    now++;
    if (now == pos) pos++, now = 2;
  }
  for (int i = 1; i <= m; i++) printf("%d %d\n", ans[i].x, ans[i].y);
  return 0;
}
