#include <bits/stdc++.h>
using namespace std;
int n, m, t, v;
vector<pair<int, int> > MST, extra;
pair<int, int> out[100100];
int main() {
  scanf("%d", &n), scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d", &v), scanf("%d", &t);
    if (t)
      MST.push_back(pair<int, int>(v, i));
    else
      extra.push_back(pair<int, int>(v, i));
  }
  sort(MST.begin(), MST.end(), greater<pair<int, int> >());
  sort(extra.begin(), extra.end(), greater<pair<int, int> >());
  for (int i = 0; i < MST.size(); ++i)
    out[MST[i].second] = pair<int, int>(i, i + 1);
  for (int i = 0, fn = 0, sn = 2; i < extra.size(); ++i) {
    while (fn < n - 2 && MST[fn].first > extra[i].first) ++fn, sn = fn + 2;
    if (fn == n - 2) return puts("-1");
    out[extra[i].second] = pair<int, int>(fn, sn);
    ++sn;
    if (sn == n) ++fn, sn = fn + 2;
  }
  for (int i = 0; i < m; ++i)
    printf("%d %d\n", out[i].first + 1, out[i].second + 1);
}
