#include <bits/stdc++.h>
using namespace std;
struct s {
  int w, t, i;
  s(int ww, int tt, int ii) : w(ww), t(tt), i(ii) {}
  bool operator<(const s& b) const {
    if (w != b.w) return w < b.w;
    return t > b.t;
  }
};
pair<int, int> p[100000];
int la, lb;
int ta, tb;
int n, m;
inline void incl() {
  la++;
  if (la == lb - 1) {
    lb++;
    la = 1;
  }
}
int main() {
  ios::sync_with_stdio(0);
  vector<s> v;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int w, t;
    cin >> w >> t;
    v.push_back(s(w, t, i));
  }
  sort(v.begin(), v.end());
  la = 1;
  lb = 3;
  ta = 1;
  tb = 2;
  int le = 0;
  for (int i = 0; i < m; i++) {
    if (!v[i].t) {
      int c = ta - 1;
      if (c * (c + 1) / 2 - c - le <= 0) {
        cout << "-1\n";
        return 0;
      }
      p[v[i].i].first = la;
      p[v[i].i].second = lb;
      incl();
      le++;
    } else {
      p[v[i].i].first = ta++;
      p[v[i].i].second = tb++;
    }
  }
  for (int i = 0; i < m; i++) cout << p[i].first << " " << p[i].second << "\n";
  return 0;
}
