#include <bits/stdc++.h>
using namespace std;
struct pack {
  int wt;
  int inc;
  int pos;
};
pack a[100005];
pair<int, int> ans[100005];
int deg[100005];
bool cmp(pack a, pack b) {
  if (a.wt != b.wt)
    return a.wt < b.wt;
  else
    return a.inc > b.inc;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i].wt >> a[i].inc;
    a[i].pos = i;
  }
  sort(a, a + m, cmp);
  int added = 1;
  int k1 = 1, k2 = 2;
  bool impossible = false;
  for (int i = 0; i < m; i++) {
    if (a[i].inc) {
      ans[a[i].pos].first = added;
      deg[added] = 1;
      ans[a[i].pos].second = ++added;
      deg[added] = 1;
    } else {
      if (k2 - k1 == 1) {
        k2++;
        k1 = 1;
      }
      if (k2 > added) {
        impossible = true;
        break;
      } else {
        ans[a[i].pos].first = k1++;
        ans[a[i].pos].second = k2;
      }
    }
  }
  if (impossible)
    cout << "-1\n";
  else {
    for (int i = 0; i < m; i++)
      cout << ans[i].first << " " << ans[i].second << endl;
  }
}
