#include <bits/stdc++.h>
using namespace std;
const char newline = '\n';
const int dy[4] = {-1, 0, 0, 1};
const int dx[4] = {0, -1, 1, 0};
const int mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int MN = 100000 + 10;
const int MM = 100000 + 10;
int ansA[MM];
int ansB[MM];
vector<tuple<int, int, int> > E;
int main(int argc, char **argv) {
  int n, m;
  int aj, bj;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &aj, &bj);
    E.push_back(make_tuple(aj, 2 - bj, i));
  }
  sort(E.begin(), E.end());
  int from, to;
  int iso = 2;
  from = 2;
  to = 3;
  bool success = true;
  int here;
  for (int i = 0; i < m; i++) {
    tie(aj, bj, here) = E[i];
    if (bj == 1) {
      ansA[here] = 1;
      ansB[here] = iso++;
    } else {
      if (iso <= to) {
        success = false;
        break;
      }
      ansA[here] = from++;
      ansB[here] = to;
      if (from == to) {
        to++;
        from = 2;
      }
    }
  }
  if (success) {
    for (int i = 1; i <= m; i++) {
      printf("%d %d\n", ansA[i], ansB[i]);
    }
  } else {
    puts("-1");
  }
  return 0;
}
