#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9 + 7;
const int N = 1e6 + 10;
vector<pair<int, int> > kq;
vector<pair<pair<int, int>, int> > d;
int n, m;
bool op(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  return (
      (a.first.first < b.first.first) ||
      ((a.first.first == b.first.first) && (a.first.second > b.first.second)));
}
void xuly() {
  sort(d.begin(), d.end(), op);
  int cnt = 1;
  int lead = 2;
  int follow = 1;
  int du = 0;
  for (int i = 0; i < m; i++) {
    if (d[i].first.second == 0) {
      if (du == 0) {
        printf("-1");
        return;
      }
      du--;
      if (lead - follow == 1) {
        lead++;
        follow = 2;
        kq[d[i].second] = make_pair(lead, follow);
      } else {
        follow++;
        kq[d[i].second] = make_pair(lead, follow);
      }
    } else {
      du += cnt - 1;
      cnt++;
      kq[d[i].second] = make_pair(1, cnt);
    }
  }
  for (int i = 0; i < m; i++) printf("%d %d\n", kq[i].first, kq[i].second);
}
int main() {
  scanf("%d%d", &n, &m);
  d.resize(m);
  kq.resize(m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &d[i].first.first, &d[i].first.second);
    d[i].second = i;
  }
  xuly();
}
