#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  ios::sync_with_stdio(false);
  solve();
}
const int N = 100001;
int n, m;
pair<int, int> ans[N];
struct edge {
  int w, mark, i;
  bool operator<(edge e) const {
    return w < e.w || (w == e.w && mark > e.mark);
  }
} e[N];
void solve() {
  while (cin >> n >> m) {
    for (int i = 0; i < m; i++) {
      int u, v;
      cin >> u >> v;
      edge ee = {u, v, i};
      e[i] = ee;
    }
    sort(e, e + m);
    bool ok = true;
    int k = 0, u = 1, v = 0;
    for (int i = 0; i < m; i++) {
      if (e[i].mark) {
        ++k;
        ans[e[i].i] = make_pair(k, k + 1);
      } else {
        if (v + 1 == u) {
          if (u < k) {
            u++;
            v = 0;
          } else {
            ok = false;
            break;
          }
        }
        ans[e[i].i] = make_pair((u + 1), (v++) + 1);
      }
    }
    if (!ok) {
      cout << -1 << endl;
    } else {
      for (int i = 0; i < m; i++)
        cout << ans[i].first << " " << ans[i].second << endl;
    }
  }
}
