#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 1000 + 7;
long long n, m, w, s, M, l = 0;
vector<pair<long long, long long> > e0, e1;
pair<long long, long long> ans[N];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> w >> s;
    if (s == 0) {
      e0.push_back({w, i});
    } else {
      e1.push_back({w, i});
    }
  }
  sort(e0.begin(), e0.end());
  sort(e1.begin(), e1.end());
  l = 0;
  for (int i = 2; i <= n; i++) {
    M = e1[i - 2].first;
    for (int j = 1; j < i - 1; j++) {
      if (l < e0.size()) {
        ans[e0[l].second] = {i, j};
        if (M > e0[l].first) {
          cout << -1;
          return 0;
        }
        l++;
      } else {
        break;
      }
    }
  }
  for (int i = 0; i < n - 1; i++) {
    ans[e1[i].second] = {i + 1, i + 2};
  }
  for (int i = 1; i <= m; i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
    ;
  }
  return 0;
}
