#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a, b;
  vector<pair<int, int> > spannum;
  vector<pair<int, int> > notspannum;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (b == 1)
      spannum.push_back(make_pair(a, i));
    else
      notspannum.push_back(make_pair(a, i));
  }
  sort(spannum.begin(), spannum.end());
  sort(notspannum.begin(), notspannum.end());
  int ver[m][2];
  for (int i = 0; i < spannum.size(); i++) {
    ver[spannum[i].second][0] = i + 1;
    ver[spannum[i].second][1] = i + 2;
  }
  int l = -1, r = 1;
  for (int i = 0; i < notspannum.size(); i++) {
    if (notspannum[i].first < spannum[r].first) {
      cout << "-1";
      return 0;
    } else {
      ver[notspannum[i].second][0] = l + 2;
      ver[notspannum[i].second][1] = r + 2;
      if (l == r - 2) {
        r++;
        l = -1;
      } else
        l++;
    }
  }
  for (int i = 0; i < m; i++) cout << ver[i][0] << " " << ver[i][1] << endl;
}
