#include <bits/stdc++.h>
using namespace std;
struct data {
  int len;
  int used;
  int id;
  data(int _len, int _used, int _id) {
    len = _len;
    used = _used;
    id = _id;
  }
};
bool comp(data x, data y) {
  if (x.len != y.len) return x.len < y.len;
  return x.used > y.used;
}
int n, m, c, l, e;
pair<int, int> ans[100005];
vector<data> E;
vector<pair<int, int> > extras;
void DNE() {
  puts("-1");
  exit(0);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0, a, b; i < m; i++) {
    scanf("%d%d", &a, &b);
    E.push_back(data(a, b, i));
    if (b) c++;
  }
  if (c != n - 1) DNE();
  l = 1;
  sort(E.begin(), E.end(), comp);
  for (int i = 0; i < m; i++) {
    if (E[i].used) {
      l++;
      ans[E[i].id].first = 1;
      ans[E[i].id].second = l;
      for (int j = 2; j < l && extras.size() < m; j++)
        extras.push_back(pair<int, int>(j, l));
    } else {
      if (e == extras.size()) DNE();
      ans[E[i].id].first = extras[e].first;
      ans[E[i].id].second = extras[e].second;
      e++;
    }
  }
  for (int i = 0; i < m; i++) printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
