#include <bits/stdc++.h>
using namespace std;
struct by_weight {
  inline bool operator()(const vector<int>& struct1,
                         const vector<int>& struct2) {
    if (struct1[0] != struct2[0])
      return struct1[0] < struct2[0];
    else
      return struct1[1] > struct2[1];
  }
};
struct by_index {
  inline bool operator()(const vector<int>& struct1,
                         const vector<int>& struct2) {
    return (struct1[2] < struct2[2]);
  }
};
void find_cycle(vector<vector<int> >& edgeM, vector<int>& vertices, int m) {
  int to = 3, from = 2;
  while (to <= vertices.size()) {
    from++;
    if (from == to) {
      to++;
      from = 2;
    }
  }
  printf("%d\n", -1);
  exit(0);
}
int main(int argc, char const* argv[]) {
  vector<int> edge(5, 0);
  int n, m, i;
  scanf("%d%d", &n, &m);
  vector<vector<int> > edgeM(m, vector<int>(5, 0));
  for (i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    edgeM[i][1] = y;
    edgeM[i][0] = x;
    edgeM[i][2] = i;
  }
  sort(edgeM.begin(), edgeM.end(), by_weight());
  if (edgeM[0][1] == 0) {
    printf("%d\n", -1);
    exit(0);
  }
  edgeM[0][3] = 1;
  edgeM[0][4] = 2;
  if (m > 1) {
    edgeM[1][3] = 1;
    edgeM[1][4] = 3;
    if (edgeM[1][1] == 0) {
      printf("%d\n", -1);
      exit(0);
    }
  }
  int index = 2;
  int last_index = 2;
  int to = 3, from = 1;
  for (i = 1; i < m; i++) {
    if (edgeM[i][1] == 1) {
      index++;
      edgeM[i][3] = 1;
      edgeM[i][4] = index;
    } else {
      from++;
      if (from == to) {
        to++;
        from = 2;
      }
      if (to > index) {
        printf("%d\n", -1);
        exit(0);
      }
      edgeM[i][3] = from;
      edgeM[i][4] = to;
    }
  }
  sort(edgeM.begin(), edgeM.end(), by_index());
  for (i = 0; i < m; i++) {
    cout << edgeM[i][3] << " " << edgeM[i][4] << endl;
  }
  return 0;
}
