#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1020304;
pair<pair<int, int>, int> A[MaxN];
int n, m;
pair<int, int> ans[MaxN];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int w, c;
    scanf("%d%d", &w, &c);
    c *= -1;
    A[i] = make_pair(make_pair(w, c), i);
  }
  sort(A + 1, A + m + 1);
  int c = 2, p = 0;
  int curlen = 1;
  for (int i = 1; i <= m; ++i) {
    int bel = A[i].second;
    pair<int, int> tmp = A[i].first;
    if (tmp.second == 0) {
      if (c > curlen) {
        puts("-1");
        return 0;
      }
      if (p + 2 < c) {
        ++p;
      } else {
        ++c;
        p = 1;
        if (c > curlen) {
          puts("-1");
          return 0;
        }
      }
      ans[bel] = make_pair(p, c);
    } else {
      ++curlen;
      ans[bel] = make_pair(curlen - 1, curlen);
    }
  }
  for (int i = 1; i <= m; ++i) printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
