#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
struct node {
  int u, v, id, w, f;
} e[N << 1];
int n, m;
bool cmp1(const node &a, const node &b) {
  if (a.w != b.w)
    return a.w < b.w;
  else
    return a.f > b.f;
}
bool cmp2(const node &a, const node &b) { return a.id < b.id; }
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  int all = 0, cnt = 1, lx = 2, rx = 3;
  for (int i = 0; i < m; ++i) {
    cin >> e[i].w >> e[i].f;
    e[i].id = i;
  }
  sort(e, e + m, cmp1);
  for (int i = 0; i < m; ++i) {
    if (e[i].f) {
      all += e[i].w;
      e[i].u = 1;
      e[i].v = ++cnt;
    } else {
      if (rx > cnt) {
        cout << -1 << endl;
        return 0;
      }
      e[i].u = lx, e[i].v = rx;
      lx--;
      if (lx == 1) {
        rx++;
        lx = rx - 1;
      }
    }
  }
  sort(e, e + m, cmp2);
  for (int i = 0; i < m; ++i) {
    cout << e[i].u << ' ' << e[i].v << endl;
  }
  return 0;
}
