#include <bits/stdc++.h>
using namespace std;
int d[100005];
pair<int, int> c[100005];
struct ppp {
  int a, b, pos;
} p[100005];
bool cmp(ppp x, ppp y) {
  if (x.a == y.a) return x.b > y.b;
  return x.a < y.a;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    d[i] = 1;
  }
  d[1] = 2;
  for (int i = 1; i <= m; i++) {
    cin >> p[i].a >> p[i].b;
    p[i].pos = i;
  }
  sort(p + 1, p + 1 + m, cmp);
  int now = 1;
  for (int i = 1; i <= m; i++) {
    if (p[i].b == 1) {
      while (now <= n && d[now] > 1) now++;
      if (now > n) {
        cout << -1 << endl;
        return 0;
      }
      c[p[i].pos] = {1, now};
      d[now]++;
    } else {
      while (now >= 1 && d[now] >= now) now--;
      if (now == 0) {
        cout << -1 << endl;
        return 0;
      }
      c[p[i].pos] = {d[now], now};
      d[now]++;
    }
  }
  for (int i = 1; i <= m; i++) {
    cout << c[i].first << " " << c[i].second << endl;
  }
}
