#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<pair<int, int>, int> > ve;
bool f() {
  sort((ve).begin(), (ve).end());
  vector<pair<int, pair<int, int> > > res;
  for (int i = 0; i < 2; i++) {
    if (ve[i].first.second == 0) {
      return false;
    } else {
      res.push_back(make_pair(ve[i].second, make_pair(0, i + 1)));
    }
  }
  int p, f, c;
  p = 3;
  f = 1;
  c = 2;
  for (int i = 2; i < ve.size(); i++) {
    if (ve[i].first.second == 0) {
      res.push_back(make_pair(ve[i].second, make_pair(f, c)));
      if (c >= p) return false;
      f++;
      if (f == c) {
        c++;
        f = 1;
      }
    } else {
      res.push_back(make_pair(ve[i].second, make_pair(0, p)));
      p++;
    }
  }
  sort((res).begin(), (res).end());
  for (int i = 0; i < m; i++) {
    printf("%d %d\n", res[i].second.first + 1, res[i].second.second + 1);
  }
  return true;
}
int main() {
  scanf("%d", &(n));
  scanf("%d", &(m));
  int w, b;
  for (int i = 0; i < m; i++) {
    scanf("%d", &(w));
    scanf("%d", &(b));
    ve.push_back(make_pair(make_pair(w, -b), i));
  }
  if (!f()) cout << "-1" << endl;
  return 0;
}
