#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  vector<pair<pair<int, int>, int>> xs(M);
  for (int i = (0); i < (M); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    xs[i] = make_pair(make_pair(a, 1 - b), i);
  }
  sort((xs).begin(), (xs).end());
  long long c = 0;
  vector<int> use;
  vector<pair<int, int>> ans(M);
  int b = 1, e = 2, n = 1;
  for (int i = 0; i < M; ++i) {
    if (xs[i].first.second == 0) {
      use.push_back(xs[i].second);
      c += n - 1;
      ++n;
      ans[xs[i].second] = make_pair(n - 1, n);
    } else {
      if (--c < 0) {
        puts("-1");
        return 0;
      }
      if (b + 1 >= e) b = 1, ++e;
      ans[xs[i].second] = make_pair(b++, e);
    }
  }
  for (int i = (0); i < (M); ++i)
    printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
