#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, z, last;
pair<int, int> ans[100005];
vector<pair<pair<int, int>, int> > v;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &x, &y);
    v.push_back(make_pair(make_pair(x, !y), i));
  }
  sort(v.begin(), v.end());
  x = 2, y = 0, last = 1;
  for (int i = 0; i < v.size(); ++i) {
    if (!v[i].first.second) {
      ans[v[i].second] = make_pair(last, last + 1);
      last++;
    } else {
      y++;
      if (x == y + 1) {
        x++;
        y = 1;
      }
      if (x > last) {
        printf("-1\n");
        return 0;
      }
      ans[v[i].second] = make_pair(y, x);
    }
  }
  for (int i = 0; i < m; ++i) printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
