#include <bits/stdc++.h>
using namespace std;
int n, m, i, f, t, ptr;
pair<pair<int, int>, int> a[100100];
bool conn[100100];
int X[100100], Y[100100];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a[i].first.first, &a[i].first.second);
    a[i].first.second ^= 1;
    a[i].second = i;
  }
  sort(a + 1, a + m + 1);
  f = 2;
  t = 3;
  ptr = 2;
  for (int i = 1; i <= m; i++) {
    if (a[i].first.second == 0) {
      X[a[i].second] = 1;
      Y[a[i].second] = ptr;
      conn[1] = conn[ptr] = 1;
      ptr++;
    } else {
      if (!conn[f] || !conn[t]) {
        puts("-1");
        exit(0);
      }
      X[a[i].second] = f;
      Y[a[i].second] = t;
      f++;
      if (f == t) {
        t++;
        f = 2;
      }
    }
  }
  for (int i = 1; i <= m; i++) printf("%d %d\n", X[i], Y[i]);
  return 0;
}
