#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000000000000000;
const long long li = 500005;
const long long mod = 1000000007;
int n, m, b[li], a[li], k, flag, t, cev;
string s;
pair<long long, long long> p[li];
vector<pair<long long, long long> > v, vv;
int main(void) {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    if (y == 1)
      v.push_back({x, i});
    else
      vv.push_back({x, i});
    if (y) cev++;
  }
  if (cev != n - 1) {
    printf("-1\n");
    return 0;
  }
  sort(v.begin(), v.end());
  sort(vv.begin(), vv.end());
  for (int i = 2; i <= n; i++) {
    a[i] = v[i - 2].first;
    p[v[i - 2].second].first = 1;
    p[v[i - 2].second].second = i;
  }
  int ind1 = 3;
  int ind2 = 2;
  for (int i = 0; i < (int)vv.size(); i++) {
    if (a[ind1] > vv[i].first) {
      printf("-1\n");
      return 0;
    }
    p[vv[i].second].first = ind1;
    p[vv[i].second].second = ind2;
    ind2--;
    if (ind2 == 1) {
      ind2 = ind1;
      ind1++;
    }
  }
  for (int i = 1; i <= m; i++) {
    printf("%lld %lld\n", p[i].first, p[i].second);
  }
  return 0;
}
