#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[100001], b[100001];
pair<int, pair<int, int> > p[100001];
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &p[i].first, &p[i].second.first);
    p[i].second.second = i;
    p[i].second.first = -p[i].second.first;
  }
  int l = 0, r = 2, k = 0;
  sort(p, p + m);
  int x = 2, y = 3;
  for (int i = 0; i < m; ++i) {
    if (p[i].second.first == -1) {
      a[p[i].second.second] = 1;
      b[p[i].second.second] = r++;
      ++k;
    } else {
      ++l;
      a[p[i].second.second] = x;
      b[p[i].second.second] = y;
      ++x;
      if (x == y) x = 2, ++y;
      if (((k + 1) * k / 2) - k - l < 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < m; ++i) {
    printf("%d %d\n", a[i], b[i]);
  }
  return 0;
}
