#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, pair<int, int>>> r(m);
  for (int i = 0; i < m; i++) {
    cin >> r[i].first >> r[i].second.first;
    r[i].second.first ^= 1;
    r[i].second.second = i;
  }
  sort((r).begin(), (r).end());
  vector<int> a(m), b(m), c(m);
  for (int i = 0; i < m; i++) {
    a[i] = r[i].first;
    b[i] = r[i].second.first ^ 1;
    c[i] = r[i].second.second;
  }
  int done = 0;
  vector<pair<int, int>> edges;
  vector<pair<int, int>> pos;
  for (int i = 0; i < m; i++) {
    if (b[i]) {
      edges.push_back({done, done + 1});
      int cur = 0;
      while (pos.size() < m && cur < done) {
        pos.push_back({cur, done + 1});
        cur++;
      }
      done++;
    } else {
      if (pos.size() == 0) {
        cout << -1 << '\n';
        return 0;
      }
      edges.push_back(pos.back());
      pos.pop_back();
    }
  }
  vector<pair<int, int>> e(m);
  for (int i = 0; i < m; i++) {
    e[c[i]] = edges[i];
  }
  for (auto u : e) {
    cout << u.first + 1 << ' ' << u.second + 1 << '\n';
  }
  return 0;
}
