#include <bits/stdc++.h>
using namespace std;
vector<tuple<int, int, int> > elek;
pair<int, int> ki[100001];
int m, n;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int s, van;
    cin >> s >> van;
    elek.push_back(make_tuple(s, -van, i));
  }
  sort(elek.begin(), elek.end());
  int hanycsucs = 1;
  int k = 1, v = 3;
  for (auto akt : elek) {
    int s = get<0>(akt), van = -get<1>(akt), mikor = get<2>(akt);
    if (van == 1) {
      hanycsucs++;
      ki[mikor] = make_pair(1, hanycsucs);
    } else {
      k++;
      if (k == v) {
        v++;
        k = 2;
      }
      if (v > hanycsucs) {
        cout << -1;
        return 0;
      }
      ki[mikor] = make_pair(k, v);
    }
  }
  for (int i = 1; i <= m; i++)
    cout << ki[i].first << ' ' << ki[i].second << endl;
}
