#include <bits/stdc++.h>
using namespace std;
int n, m;
pair<pair<int, int>, int> e[123456];
int main() {
  scanf("%d %d ", &n, &m);
  int a, b;
  bool pos = true;
  int cnt = 0;
  vector<pair<int, int> > fre;
  vector<pair<int, int> > ret;
  ret.resize(m);
  int last = 1;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    e[i] = pair<pair<int, int>, int>(pair<int, int>(a, 1 - b), i);
  }
  sort(e, e + m);
  for (int i = 0; i < m; i++) {
    a = e[i].first.first;
    b = 1 - e[i].first.second;
    if (b == 1) {
      ret[e[i].second] = pair<int, int>(last, last + 1);
      last++;
      cnt++;
      for (int i = 1; i < last - 1; i++) {
        fre.push_back(pair<int, int>(last, i));
        cnt++;
        if (cnt > m) break;
      }
    } else {
      if (fre.empty()) {
        pos = false;
        break;
      } else {
        pair<int, int> tmp = fre.back();
        fre.pop_back();
        ret[e[i].second] = tmp;
      }
    }
  }
  if (pos) {
    for (auto x : ret) printf("%d %d\n", x.first, x.second);
  } else {
    printf("-1\n");
  }
  return 0;
}
