#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, pair<int, int> > > E(m);
  {
    int cnt = 0;
    for (int i = 0; i < m; i++) {
      cin >> E[i].first >> E[i].second.first;
      E[i].second.second = i;
      if (E[i].second.first == 1) cnt++;
      E[i].second.first = 1 - E[i].second.first;
    }
    if (cnt != n - 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  sort(E.begin(), E.end());
  vector<pair<int, int> > res(m);
  queue<pair<int, int> > que;
  int latest = 1;
  for (int i = 0; i < m; i++) {
    if (E[i].second.first == 0) {
      res[E[i].second.second] = make_pair(latest, latest + 1);
      for (int u = 1; u < latest && que.size() < m; u++)
        que.push(make_pair(u, latest + 1));
      latest++;
    } else {
      if (que.empty()) {
        cout << -1 << endl;
        return 0;
      } else {
        auto v = que.front();
        que.pop();
        res[E[i].second.second] = v;
      }
    }
  }
  for (int i = 0; i < m; i++)
    cout << res[i].first << " " << res[i].second << endl;
  return 0;
}
