#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> inside;
vector<pair<int, int>> outside;
vector<pair<int, pair<int, int>>> ans;
int main() {
  int n, m, w, b;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> w >> b;
    if (b == 0) {
      outside.push_back({w, i});
    }
    if (b == 1) {
      inside.push_back({w, i});
    }
  }
  sort(outside.begin(), outside.end());
  sort(inside.begin(), inside.end());
  int tmp = 1;
  int f = 0;
  for (int i = 0; i < inside.size(); i++) {
    tmp++;
    ans.push_back({inside[i].second, {1, tmp}});
    if (f < outside.size()) {
      for (int j = 0; j < i; j++) {
        if (f == outside.size()) {
          break;
        }
        if (outside[f].first < inside[i].first) {
          cout << -1;
          return 0;
        } else {
          ans.push_back({outside[f].second, {tmp, j + 2}});
          f++;
        }
      }
    }
  }
  sort(ans.begin(), ans.end());
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].second.first << " " << ans[i].second.second << endl;
  }
}
