#include <bits/stdc++.h>
using namespace std;
pair<pair<int, int>, int> edges[100009];
pair<int, int> edg[100009];
bool cmp(pair<pair<int, int>, int> A, pair<pair<int, int>, int> B) {
  if (A.first.first == B.first.first)
    return A.first.second > B.first.second;
  else
    return A.first.first < B.first.first;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int c, p;
    scanf("%d%d", &c, &p);
    edges[i].first = pair<int, int>(c, p);
    edges[i].second = i;
  }
  sort(edges, edges + m, cmp);
  int lv = 2;
  int from = 2;
  int to = 3;
  for (int i = 0; i < m; i++) {
    int p = edges[i].first.second;
    int ind = edges[i].second;
    if (p == 1) {
      edg[ind] = pair<int, int>(1, lv);
      lv++;
    } else if (p == 0) {
      if (from == to) {
        to++;
        from = 2;
      }
      if (to >= lv) {
        printf("-1\n");
        return 0;
      }
      edg[ind] = pair<int, int>(from, to);
      from++;
    }
  }
  for (int i = 0; i < m; i++) {
    printf("%d %d\n", edg[i].first, edg[i].second);
  }
  return 0;
}
