#include <bits/stdc++.h>
using namespace std;
const int N = 100001, md = 1e9 + 7;
using namespace std;
int n, m, x, y, len, last, pre, a[N];
pair<int, pair<int, int> > g[N];
vector<pair<int, int> > ans;
int main() {
  scanf("%d%d", &n, &m);
  ans.resize(m + 1);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &g[i].first, &g[i].second.first);
    g[i].second.first = 1 - g[i].second.first;
    g[i].second.second = i;
  }
  sort(g + 1, g + m + 1);
  last = 1;
  pre = 1;
  for (int i = 1; i <= m; i++) {
    if (!g[i].second.first) {
      last++;
      ans[g[i].second.second].first = last - 1;
      ans[g[i].second.second].second = last;
      a[last - 1]++;
      pre = 1;
    } else {
      while (pre <= last && pre + a[pre] + 1 > last) pre++;
      if (pre > last) {
        puts("-1");
        return 0;
      }
      ans[g[i].second.second].first = pre;
      ans[g[i].second.second].second = a[pre] + pre + 1;
      a[pre]++;
    }
  }
  for (int i = 1; i <= m; i++) printf("%d %d\n", ans[i].first, ans[i].second);
}
