#include <bits/stdc++.h>
using namespace std;
int const N = 312312;
int const INF = 1e9 + 7;
set<pair<int, int> > st;
int n, m;
pair<int, int> ans[N];
vector<pair<int, pair<int, int> > > v;
map<int, bool> used;
bool co(pair<int, pair<int, int> > fi, pair<int, pair<int, int> > se) {
  if (fi.first != se.first) return fi.first < se.first;
  return fi.second.first > se.second.first;
}
int main() {
  cin >> n >> m;
  for (int c = 1; c <= m; c++) {
    int x, y;
    cin >> x >> y;
    v.push_back({x, {y, c}});
  }
  sort(v.begin(), v.end(), co);
  int cnt = 2;
  int from = 2, to = 3;
  for (int c = 0; c < v.size(); c++) {
    int x = v[c].first, y = v[c].second.first;
    if (y) {
      ans[v[c].second.second] = {1, cnt};
      used[cnt] = true;
      used[1] = true;
      cnt++;
    } else {
      if (!used[to]) {
        puts("-1");
        return 0;
      }
      ans[v[c].second.second] = {from, to};
      used[from] = used[to] = true;
      from++;
      if (from == to) {
        to++;
        from = 2;
      }
    }
  }
  for (int c = 1; c <= m; c++) {
    cout << ans[c].first << " " << ans[c].second << endl;
  }
  return 0;
}
