#include <bits/stdc++.h>
using namespace std;
int n, m;
pair<pair<int, int>, int> e[111111];
pair<int, int> res[111111];
void imp() {
  puts("-1");
  exit(0);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    e[i].first = make_pair(a, -b);
    e[i].second = i;
  }
  sort(e, e + m);
  int in = 1;
  int out = 1;
  int to = 1;
  for (int i = 0; i < m; i++) {
    int num = e[i].second;
    int part = e[i].first.second;
    if (part == 0) {
      if (to >= in) {
        in++;
        to = 1;
      }
      if (in >= out) {
        imp();
      }
      res[num] = make_pair(to, in);
      ++to;
    } else {
      res[num] = make_pair(0, out);
      out++;
    }
  }
  for (int i = 0; i < m; i++) {
    printf("%d %d\n", res[i].first + 1, res[i].second + 1);
  }
  return 0;
}
