#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7, K = 5e2 + 7, inf = 1e9 + 7;
const double eps = 1e-9;
int i, n, m, x, y, v, j, kvo;
pair<int, int> ans[N];
vector<pair<int, int> > a, b;
int main() {
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    if (y == 1) {
      a.push_back(make_pair(x, i));
    } else {
      b.push_back(make_pair(x, i));
    }
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  for (i = 0; i < a.size(); i++) {
    ans[a[i].second] = make_pair(i + 1, i + 2);
    kvo++;
  }
  j = b.size() - 1;
  for (i = a.size() - 1; i >= 0; i--) {
    v = i;
    while (j >= 0 && a[i].first <= b[j].first && a[v - 1].first <= b[j].first &&
           v >= 1) {
      ans[b[j].second] = make_pair(i + 2, v);
      kvo++;
      v--;
      j--;
    }
  }
  if (kvo < m) {
    cout << -1 << endl;
  } else {
    for (i = 0; i < m; i++) {
      cout << ans[i].first << " " << ans[i].second << endl;
    }
  }
}
