#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
const int INF = 1000000007;
struct edge {
  int weight;
  int inMST;
} e[N];
int n, m, uu[N], vv[N], id[N];
bool cmp(int A, int B) {
  return (e[A].weight < e[B].weight) ||
         (e[A].weight == e[B].weight && e[A].inMST > e[B].inMST);
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &e[i].weight, &e[i].inMST);
    id[i] = i;
  }
  sort(id + 1, id + m + 1, cmp);
  int curr = 1, last1 = 0, last2 = 3;
  for (int ii = 1; ii <= m; ii++) {
    int i = id[ii];
    int u, v;
    if (e[i].inMST) {
      u = curr;
      curr++;
      v = curr;
    } else {
      last1++;
      if (last1 == last2 - 1) {
        last1 = 1;
        last2++;
      }
      if (last2 > curr) {
        cout << -1 << endl;
        return 0;
      }
      u = last1;
      v = last2;
    }
    uu[i] = u;
    vv[i] = v;
  }
  for (int i = 1; i <= m; i++) printf("%d %d\n", uu[i], vv[i]);
  return 0;
}
