#include <bits/stdc++.h>
using namespace std;
long long D[100005] = {0};
unordered_map<long long, vector<long long> > minc;
unordered_map<long long, vector<pair<long long, long long> > > mdec;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> inc, dec;
  vector<pair<long long, long long> > v;
  while (m--) {
    long long x, y;
    cin >> x >> y;
    v.push_back(make_pair(x, y));
    if (y)
      inc.push_back(x);
    else
      dec.push_back(x);
  }
  sort((inc).begin(), (inc).end());
  for (long long i = 0; i <= (long long)inc.size() - 1; i++) {
    minc[inc[i]].push_back(i + 2);
  }
  sort((dec).begin(), (dec).end());
  for (long long i = inc.size() - 1; i >= 0; i--) {
    if (dec.empty()) goto pr;
    if (dec.back() < inc[i]) continue;
    for (long long j = i - 1; j >= 0; j--) {
      if (dec.empty()) goto pr;
      long long x = i + 2, y = j + 2;
      if (dec.back() >= inc[i] && dec.back() >= inc[j]) {
        mdec[dec.back()].push_back(make_pair(x, y));
        dec.pop_back();
      }
    }
  }
  if (!dec.empty()) {
    cout << "-1";
    return 0;
  }
pr:
  for (auto p : v) {
    if (p.second == 1) {
      cout << "1 " << minc[p.first].back() << "\n";
      minc[p.first].pop_back();
    } else {
      cout << mdec[p.first].back().first << " " << mdec[p.first].back().second
           << "\n";
      mdec[p.first].pop_back();
    }
  }
}
