#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, int> > e;
vector<pair<int, pair<int, int> > > ans;
int main() {
  int n, m, i, j, x, b, pt;
  scanf("%d", &n);
  scanf("%d", &m);
  e.clear();
  for (i = 0; i < m; i++) {
    scanf("%d", &x);
    scanf("%d", &b);
    b = 1 - b;
    e.push_back(make_pair(make_pair(x, b), i));
  }
  sort(e.begin(), e.end());
  pt = 2;
  int p1 = 1, p2 = 3;
  int cnt = 0;
  long long av;
  ans.clear();
  for (i = 0; i < m; i++) {
    x = e[i].first.first;
    b = e[i].first.second;
    b = 1 - b;
    int ind = e[i].second;
    if (b) {
      ans.push_back(make_pair(ind, make_pair(pt - 1, pt)));
      pt++;
    } else {
      cnt++;
      av = 1LL * (pt - 2LL) * (pt - 3LL) / 2LL;
      if (av < cnt) {
        puts("-1");
        return 0;
      }
      ans.push_back(make_pair(ind, make_pair(p1, p2)));
      p1++;
      if (p1 + 1 == p2) {
        p2++;
        p1 = 1;
      }
    }
  }
  sort(ans.begin(), ans.end());
  for (i = 0; i < m; i++)
    printf("%d %d\n", ans[i].second.first, ans[i].second.second);
  return 0;
}
