#include <bits/stdc++.h>
using namespace std;
pair<int, pair<int, int> > a[1000010];
pair<int, int> d[1000010];
int n, m, f[1000010];
bool comp(pair<int, pair<int, int> > p, pair<int, pair<int, int> > q) {
  return p.first < q.first ||
         (p.first == q.first && p.second.first > q.second.first);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) cin >> a[i].first >> a[i].second.first;
  for (int i = 1; i <= m; i++) a[i].second.second = i;
  sort(a + 1, a + m + 1, comp);
  priority_queue<pair<int, int> > q;
  int k = 1;
  q.push(make_pair(-3, 1));
  for (int i = 1; i <= m; i++) {
    if (a[i].second.first == 1) {
      d[a[i].second.second] = make_pair(k, k + 1);
      k++;
      if (k < n - 1) q.push(make_pair(-(k + 2), k));
    } else {
      int v = -q.top().first;
      int u = q.top().second;
      q.pop();
      if (v > k) {
        cout << -1;
        return 0;
      }
      d[a[i].second.second] = make_pair(u, v);
      q.push(make_pair(-(v + 1), u));
    }
  }
  for (int i = 1; i <= m; i++) cout << d[i].first << " " << d[i].second << endl;
  return 0;
}
