#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<pair<int, int> > A;
map<pair<int, int>, int> Ma;
pair<int, int> res[100005];
int main() {
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      T, NT;
  cin >> N >> M;
  for (int(i) = (0); ((i)) < ((M)); ++(i)) {
    int a, b;
    cin >> a >> b;
    if (b)
      T.push(make_pair(a, i));
    else
      NT.push(make_pair(a, i));
  }
  int p = 0;
  while (!T.empty()) {
    pair<int, int> t = T.top();
    T.pop();
    res[t.second] = make_pair(p, p + 1);
    Ma[make_pair(p, p + 1)] = t.first;
    p++;
  }
  int weight = 0;
  for (int i = 1; i < N; i++) {
    weight = Ma[make_pair(i - 1, i)];
    for (int j = 0; j < i - 1; j++) {
      if (NT.empty()) {
        for (int(k) = (0); ((k)) < ((M)); ++(k))
          cout << res[k].first + 1 << " " << res[k].second + 1 << endl;
        return 0;
      } else {
        pair<int, int> nt = NT.top();
        NT.pop();
        if (nt.first >= weight) {
          res[nt.second] = make_pair(i, j);
        } else {
          cout << -1 << endl;
          return 0;
        }
      }
    }
  }
  if (NT.empty()) {
    for (int(k) = (0); ((k)) < ((M)); ++(k))
      cout << res[k].first + 1 << " " << res[k].second + 1 << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
