#include <bits/stdc++.h>
using namespace std;
bool toCompare(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  if (a.first.first < b.first.first)
    return true;
  else if ((a.first.first == b.first.first) && (a.first.second == 1) &&
           (b.first.second == 0))
    return true;
  return false;
}
int main() {
  int n, m, from = 1, to = 2, N = 1;
  vector<pair<pair<int, int>, int> > ab;
  cin >> n >> m;
  vector<pair<int, int> > ans(m + 10);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    ab.push_back(make_pair(make_pair(a, b), i));
  }
  sort(ab.begin(), ab.end(), toCompare);
  for (int i = 0; i < m; i++)
    if (ab[i].first.second == 1)
      ans[ab[i].second] = make_pair(1, ++N);
    else {
      from++;
      if (from == to)
        if (to < N) {
          to++;
          from = 2;
        } else {
          puts("-1");
          return 0;
        }
      ans[ab[i].second] = make_pair(from, to);
    }
  for (int i = 0; i < m; i++) printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
