#include <bits/stdc++.h>
using namespace std;
pair<int, int> ans[100007];
int final[1000007];
struct node {
  int val;
  bool inmst;
  int idx;
} edge[1000007];
bool compare(node l, node r) {
  if (l.val == r.val) {
    return (l.inmst > r.inmst);
  }
  return (l.val < r.val);
}
int main() {
  int n, m, i, curr, cycle, pos, start, end, flag, j;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> edge[i].val >> edge[i].inmst;
    edge[i].idx = i;
  }
  sort(edge, edge + m, compare);
  curr = 1;
  cycle = 0;
  flag = 0;
  pos = 0;
  start = 1;
  end = 2;
  for (i = 1; i <= n; i++) final[i] = i + 1;
  for (i = 0; i < m; i++) {
    if (edge[i].inmst) {
      ans[edge[i].idx] = make_pair(curr, curr + 1);
      curr++;
    } else {
      cycle++;
      if (cycle > ((curr * (curr - 1)) / 2 - (curr - 1))) {
        flag = 1;
        break;
      } else {
        for (j = 1; j < curr; j++) {
          if (final[j] < curr) {
            ans[edge[i].idx] = make_pair(j, final[j] + 1);
            final[j]++;
            break;
          }
        }
      }
    }
  }
  if (curr > n) flag = 1;
  if (flag)
    cout << "-1\n";
  else {
    for (i = 0; i < m; i++) {
      cout << ans[i].first << " " << ans[i].second << "\n";
    }
  }
  return 0;
}
