#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<pair<int, int>, int> > e;
int f = 1, t = 0, upto = 1;
bool NextEdge() {
  if (t + 1 < f)
    ++t;
  else if (f == upto)
    return false;
  else
    ++f, t = 1;
  return true;
}
void SayNo() {
  printf("-1\n");
  exit(0);
}
int main() {
  scanf("%d%d", &n, &m);
  e.resize(m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &e[i].first.first, &e[i].first.second);
    e[i].first.second = 1 - e[i].first.second;
    e[i].second = i;
  }
  sort(e.begin(), e.end());
  set<pair<int, int> > nal;
  vector<pair<int, int> > ans(m);
  for (int i = 0; i < ((int)(e).size()); ++i) {
    if (e[i].first.second == 0) {
      int le = 1;
      int re = ++upto;
      ans[e[i].second] = make_pair(le, re);
      nal.insert(make_pair(le, re));
    } else {
      for (;;) {
        if (!NextEdge()) SayNo();
        if (!nal.count(make_pair(f, t)) && !nal.count(make_pair(t, f))) break;
      }
      ans[e[i].second] = make_pair(f, t);
    }
  }
  for (int i = 0; i < ((int)(ans).size()); ++i)
    printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
