#include <bits/stdc++.h>
using namespace std;
const int nmax = 300010;
int n, m;
pair<int, int> ans[nmax];
queue<pair<int, int> > q;
pair<pair<int, int>, int> edges[nmax];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &edges[i].first.first, &edges[i].first.second);
    edges[i].first.second *= -1;
    edges[i].second = i;
  }
  sort(edges, edges + m);
  int cnt = 1;
  for (int i = 0; i < m; i++) {
    int type = edges[i].first.second;
    if (type == 0) {
      if (q.empty()) {
        printf("-1\n");
        return 0;
      }
      ans[edges[i].second] = q.front();
      q.pop();
    } else {
      cnt++;
      {
        for (int j = 2; j < cnt && q.size() < m; j++) q.push(make_pair(j, cnt));
      }
      ans[edges[i].second] = make_pair(1, cnt);
    }
  }
  for (int i = 0; i < m; i++) printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
