#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {
  if (a.first != b.first)
    return a.first < b.first;
  else
    return a.second.first > b.second.first;
}
int main() {
  int n, m;
  cin >> n >> m;
  pair<int, int> p[m];
  pair<int, pair<int, int> > p1[m];
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &p1[i].first, &p1[i].second.first);
    p1[i].second.second = i;
  }
  sort(p1, p1 + m, cmp);
  int ct = n - 1, k = 2;
  int val[n + 2], kit[n + 2];
  for (int i = 1; i <= n; i++) {
    val[i] = n - i - 1;
    kit[i] = 2;
  }
  int from = 1, to = 3;
  for (int i = 0; i < m; i++) {
    if (ct > 0 && p1[i].second.first == 1) {
      p[p1[i].second.second] = make_pair(k, k - 1);
      k++;
      ct--;
    } else {
      if (from == to - 1) {
        to++;
        from = 1;
        if (to >= k) {
          printf("-1");
          return 0;
        }
        p[p1[i].second.second] = make_pair(from, to);
        from++;
      } else {
        if (to >= k) {
          printf("-1");
          return 0;
        }
        p[p1[i].second.second] = make_pair(from, to);
        from++;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    printf("%d %d\n", p[i].first, p[i].second);
  }
  return 0;
}
