#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
bool comp(vector<long long> &a, vector<long long> &b) {
  if (a[0] == b[0]) return a[1] > b[1];
  return a[0] < b[0];
}
int main() {
  long long n, m;
  cin >> n >> m;
  vector<vector<long long>> mst(m);
  for (long long i = 0; i < m; i++) {
    long long w, inc;
    cin >> w >> inc;
    mst[i] = {w, inc, i};
  }
  sort(mst.begin(), mst.end(), comp);
  vector<pair<long long, long long>> ans(m);
  long long node = 1;
  long long u = 1, v = 3;
  for (long long i = 0; i < m; i++) {
    long long inc = mst[i][1], idx = mst[i][2];
    if (inc) {
      ans[idx] = {node, node + 1};
      node++;
    } else {
      if (v > node) {
        cout << -1;
        return 0;
      }
      ans[idx] = {u, v};
      if (u < v - 2) {
        u++;
      } else
        u = 1, v++;
    }
  }
  for (auto p : ans) {
    cout << p.first << " " << p.second << "\n";
  }
  return 0;
}
