#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
pair<int, int> b[100100];
vector<int> q;
pair<int, pair<int, int> > a[100100];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i].first >> a[i].second.first;
    a[i].second.first = 1 - a[i].second.first;
    a[i].second.second = i;
  }
  sort(a, a + m);
  int p = 0, k = 1, un = 0, uk = -1;
  for (int i = 0; i < m; i++) {
    if (a[i].second.first == 1 && p == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (a[i].second.first == 0) {
      p += k - 1;
      k++;
      q.push_back(k);
      b[a[i].second.second] = make_pair(1, k);
    } else {
      if (uk == -1) {
        un++;
        uk = un - 1;
      }
      b[a[i].second.second] = make_pair(q[uk], q[un]);
      uk--;
      p--;
    }
  }
  for (int i = 0; i < m; i++) cout << b[i].first << ' ' << b[i].second << endl;
  return 0;
}
