#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000007, maxn = 444444;
long long gcd(long long a, long long b) { return (a ? gcd(b % a, 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 x = 2, y = 3, n, m, ridam = 1, a, b;
pair<long long, bool> shahsavari[100100];
pair<pair<long long, bool>, long long> antikonkor[100100];
pair<long long, long long> kompoot[100100];
bool s;
int main() {
  cin >> n >> m;
  for (long long(i) = 0; (i) < (m); (i)++) {
    cin >> shahsavari[i].first;
    cin >> s;
    shahsavari[i].second = !s;
    antikonkor[i] = {shahsavari[i], i};
  }
  sort(antikonkor, antikonkor + m);
  for (long long(i) = 0; (i) < (m); (i)++)
    if (antikonkor[i].first.second)
      if (a >= b * (b - 1) / 2)
        return cout << -1, 0;
      else {
        a++;
        kompoot[antikonkor[i].second] = {x, y};
        if (x == y - 1) {
          y++;
          x = 2;
        } else
          x++;
      }
    else {
      b++;
      kompoot[antikonkor[i].second] = {1, ++ridam};
    }
  for (long long(i) = 0; (i) < (m); (i)++)
    cout << kompoot[i].first << " " << kompoot[i].second << "\n";
}
