#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<pair<pair<int, int>, int> > E;
pair<int, int> ans[100009];
void Init() {
  scanf("%d%d", &N, &M);
  E.clear();
  for (int i = 1; i <= M; i++) {
    int w, b;
    scanf("%d%d", &w, &b);
    E.push_back(make_pair(make_pair(w, 0 - b), i));
  }
  sort(E.begin(), E.end());
}
void Solve() {
  int sum = 1, sumNo = 0, uu = 3, vv = 0;
  for (int i = 0; i < E.size(); i++) {
    pair<pair<int, int>, int> it = E[i];
    if (it.first.second == -1) {
      sum++;
      ans[it.second] = make_pair(sum - 1, sum);
    } else {
      sumNo++;
      if ((long long)sumNo >
          (long long)sum * (long long)(sum - 1) / 2LL - (long long)(sum - 1)) {
        puts("-1");
        return;
      } else {
        if (vv + 1 == uu || vv + 2 == uu) {
          vv = 1;
          uu++;
        } else
          vv++;
        ans[it.second] = make_pair(uu, vv);
      }
    }
  }
  for (int i = 1; i <= M; i++) printf("%d %d\n", ans[i].first, ans[i].second);
}
int main() {
  Init();
  Solve();
}
