#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<pair<int, int>, int> p1, pair<pair<int, int>, int> p2) {
  if (p1.first.first < p2.first.first) return true;
  if (p1.first.first == p2.first.first) {
    if (p1.first.second > p2.first.second) return true;
    if (p1.first.second == p2.first.second) p1.second < p2.second;
    return false;
  }
  return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<pair<int, int>, int> > edges(m);
  for (int i = 0; i < m; i++) {
    cin >> edges[i].first.first >> edges[i].first.second;
    edges[i].second = i;
  }
  sort(edges.begin(), edges.end(), cmp);
  queue<pair<int, int> > q;
  vector<pair<int, int> > ans(m);
  int cur_node = 1;
  for (int i = 0; i < m; i++) {
    pair<pair<int, int>, int> p = edges[i];
    int id = p.second;
    if (p.first.second) {
      ans[id] = pair<int, int>(0, cur_node);
      for (int u = 1; u < cur_node; u++) {
        if ((int)q.size() >= m) break;
        q.emplace(cur_node, u);
      }
      cur_node += 1;
    } else {
      if (q.empty()) {
        cout << "-1\n";
        return 0;
      }
      ans[id] = q.front();
      q.pop();
    }
  }
  for (pair<int, int> p : ans) {
    cout << p.first + 1 << ' ' << p.second + 1 << "\n";
  }
  return 0;
}
