#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, mod = 1e9 + 7;
const int maxn = 2e5 + 100, mxn = 5e5 + 100;
const long double PI = acos(-1.0);
long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }
void exgcd(long long a, long long b, long long& d, long long& x, long long& y) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    exgcd(b, a % b, d, y, x);
    y -= x * (a / b);
  }
}
long long power(long long a, long long n) {
  long long p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
    }
    n >>= 1;
    a *= a;
  }
  return p;
}
long long power(long long a, long long n, long long mod) {
  long long p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
      p %= mod;
    }
    n >>= 1;
    a *= a;
    a %= mod;
  }
  return p % mod;
}
int n, m;
int uu[maxn], vv[maxn];
struct veg {
  int num, va, fl;
  bool operator<(const veg& a) const {
    if (va == a.va) return fl > a.fl;
    return va < a.va;
  }
} we[maxn];
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      we[i].va = u;
      we[i].num = i;
      we[i].fl = v;
    }
    sort(we + 1, we + 1 + m);
    int maxx = 1, r = 2, l = 2, flv = 1;
    for (int i = 1; i <= m; i++) {
      if (we[i].fl == 1) {
        maxx++;
        uu[we[i].num] = 1;
        vv[we[i].num] = maxx;
      } else {
        if (l == 2) {
          r++;
          l = r;
          if (r > maxx) {
            flv = 0;
            break;
          }
        }
        uu[we[i].num] = r;
        vv[we[i].num] = l - 1;
        l--;
      }
    }
    if (flv == 0)
      cout << -1 << endl;
    else {
      for (int i = 1; i <= m; i++) printf("%d %d\n", uu[i], vv[i]);
    }
  }
  return 0;
}
