#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
pair<int, pair<int, int>> a[N];
pair<int, int> b[N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int t, tt;
    scanf("%d %d", &t, &tt);
    tt ^= 1;
    a[i] = {t, {tt, i}};
  }
  sort(a, a + m);
  long long cnt = 1, mx = 0;
  bool f = 1;
  int x = 1, y = 2;
  for (int i = 0, j; i < m; i++) {
    pair<int, int> tt = a[i].second;
    j = tt.second;
    if (tt.first) {
      if (i >= mx) {
        f = 0;
        break;
      } else {
        x++;
        if (x == y) {
          x = 2;
          y++;
        }
        b[j] = {x, y};
      }
    } else {
      cnt++;
      b[j] = {1, (int)cnt};
      mx = (cnt - 1) * cnt / 2;
    }
  }
  if (f) {
    for (int i = 0; i < m; i++) printf("%d %d\n", b[i].first, b[i].second);
  } else
    puts("-1");
  return 0;
}
