#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const int mod = 1e9 + 7;
const int MAXN = 1e5 * 5 + 5;
struct st {
  int c, t, num;
};
bool cmp(st a, st b) {
  if (a.c < b.c) return true;
  if (a.c > b.c) return false;
  return a.t > b.t;
}
int main() {
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  if (m < n - 1) {
    cout << -1;
    return 0;
  }
  vector<st> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i].c >> a[i].t;
    a[i].num = i;
  }
  sort(a.begin(), a.end(), cmp);
  vector<pair<int, int>> res(m);
  int k = 2, from = 2, to = 3, f = false;
  for (int i = 0; i < m; i++) {
    if (a[i].t) {
      res[a[i].num] = {1, k};
      k++;
    } else {
      if (to >= k)
        return 0 * puts("-1");
      else {
        res[a[i].num] = {from, to};
        from++;
        if (from == to) {
          to++;
          from = 2;
        }
      }
    }
  }
  for (int i = 0; i < m; i++) {
    cout << res[i].first << " " << res[i].second << '\n';
  }
  return 0;
}
