#include <bits/stdc++.h>
using namespace std;
vector<pair<int, pair<int, int> > > vec;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    b = !b;
    vec.push_back({a, {b, i}});
  }
  sort(vec.begin(), vec.end());
  vector<pair<int, pair<int, int> > > ans;
  int cur = 1, all = 1, r = 1;
  for (int i = 0; i < m; i++) {
    if (vec[i].second.first == 0) {
      all++;
      ans.push_back({vec[i].second.second, {1, all}});
      continue;
    }
    if (r == cur) {
      cur++;
      r = 2;
      if (r == cur) {
        cur++;
      }
    }
    if (cur > all) {
      cout << -1;
      return 0;
    }
    ans.push_back({vec[i].second.second, {cur, r}});
    r++;
  }
  if (all != n) {
    cout << -1;
    return 0;
  }
  sort(ans.begin(), ans.end());
  for (int i = 0; i < m; i++) {
    cout << ans[i].second.first << " " << ans[i].second.second << '\n';
  }
  cout << endl;
  return 0;
}
