#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<pair<int, int> > pasang, mst;
int sol_fr[100005], sol_to[100005];
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (b == 1)
      mst.push_back({a, i});
    else
      pasang.push_back({a, i});
  }
  sort(mst.begin(), mst.end());
  sort(pasang.begin(), pasang.end());
  reverse(pasang.begin(), pasang.end());
  for (int i = 0; i < N - 1; i++) {
    int id = mst[i].second;
    int skor = mst[i].first;
    sol_fr[id] = i;
    sol_to[id] = i + 1;
  }
  int j = N - 2;
  int k = 0;
  int X = pasang.size();
  for (int i = 0; i < X; i++) {
    int id = pasang[i].second;
    int skor = pasang[i].first;
    while (j >= 0 && skor < mst[j].first) {
      j--;
      k = 0;
    }
    if (j <= 0) {
      cout << -1 << endl;
      return 0;
    }
    sol_fr[id] = j + 1;
    sol_to[id] = k;
    k++;
    if (k == j) {
      j--;
      k = 0;
    }
  }
  for (int i = 0; i < M; i++) {
    printf("%d %d\n", sol_fr[i] + 1, sol_to[i] + 1);
  }
}
