#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &a) {
  a = 0;
  char c;
  bool f = 0;
  while (!isdigit(c = getchar()) && c != '-')
    ;
  if (c == '-') f = 1, c = getchar();
  do a = a * 10 + c - '0';
  while (isdigit(c = getchar()));
  if (f) a = -a;
}
const int MAXN = 111111;
const int MAXM = 111111;
struct Edge {
  int v, f, x, y, id;
} E[MAXM], ans[MAXM];
bool cmp(const Edge &a, const Edge &b) {
  return a.v < b.v || (a.v == b.v && a.f && !b.f);
}
int n, m;
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= m; ++i) E[i].id = i, read(E[i].v), read(E[i].f);
  stable_sort(E + 1, E + m + 1, cmp);
  int tail = 1, failx = 1, faily = 0;
  for (int i = 1; i <= m; ++i) {
    if (E[i].f) {
      ++tail;
      E[i].x = 1;
      E[i].y = tail;
    } else {
      for (++faily; failx == faily; ++failx, faily = 2)
        ;
      if (failx > tail) {
        puts("-1");
        return 0;
      }
      E[i].y = failx;
      E[i].x = faily;
    }
  }
  for (int i = 1; i <= m; ++i) ans[E[i].id] = E[i];
  for (int i = 1; i <= m; ++i) printf("%d %d\n", ans[i].x, ans[i].y);
  return 0;
}
