#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int N = 101000;
int n, m;
pair<int, pair<int, int> > p[N];
pair<int, int> e[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &p[i].first, &p[i].second.first);
    p[i].second.first *= -1;
    p[i].second.second = i;
  }
  sort(p, p + m);
  int cnt = 0;
  long long E = 0;
  pair<int, int> pre = make_pair(2, 1);
  for (int i = 0; i < m; i++) {
    int id = p[i].second.second;
    if (p[i].second.first == -1) {
      cnt++;
      E += cnt;
      e[id] = make_pair(0, cnt);
    } else {
      if (E == 0) {
        puts("-1");
        return 0;
      } else {
        e[id] = pre;
        pre.second++;
        if (pre.second == pre.first) pre.first++, pre.second = 1;
      }
    }
    --E;
  }
  for (int i = 0; i < m; i++) {
    printf("%d %d\n", e[i].first + 1, e[i].second + 1);
  }
}
