#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e5 + 7, Inf = 1e5;
int m, n, t[Maxn], maj[Maxn], majw;
pair<int, int> ans[Maxn];
vector<pair<pair<int, int>, int> > g;
int main() {
  cin >> n >> m;
  for (int i = 0, a, b; i < m; i++) {
    cin >> a >> b;
    g.push_back(make_pair(make_pair(a, -1 * b), i));
  }
  sort(g.begin(), g.end());
  int ka = 1, kb = 2, kc = 1;
  for (int i = 0; i < (int)g.size(); i++) {
    if (g[i].first.second == -1) {
      ans[g[i].second] = make_pair(0, ka), ka++;
    } else {
      if (kc == 0) kb++, kc = kb - 1;
      if (kb >= ka || kc == 0) {
        cout << -1;
        return 0;
      }
      ans[g[i].second] = make_pair(kb, kc), kc--;
    }
  }
  for (int i = 0; i < m; i++) {
    cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
  }
}
