#include <bits/stdc++.h>
const int N = 100100;
struct Edge {
  int weight, type;
  int x, y;
  int num;
  bool operator<(const Edge& other) const {
    return weight == other.weight ? type > other.type : weight < other.weight;
  }
} edges[N];
int n, m;
int x[N], y[N];
bool b[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &edges[i].weight, &edges[i].type);
    edges[i].num = i;
  }
  std::sort(edges, edges + m);
  int k = 0;
  int ptrX = 0, ptrY = 2;
  for (int i = 0; i < m; ++i) {
    if (edges[i].type == 0) {
      if (b[ptrX] && b[ptrY]) {
        edges[i].x = ptrX;
        edges[i].y = ptrY;
        if (ptrX + 2 < ptrY)
          ++ptrX;
        else {
          ptrX = 0;
          ++ptrY;
        }
      } else {
        puts("-1");
        return 0;
      }
    } else {
      edges[i].x = k;
      edges[i].y = k + 1;
      b[k] = true;
      b[k + 1] = true;
      ++k;
    }
  }
  for (int i = 0; i < m; ++i) {
    int num = edges[i].num;
    x[num] = edges[i].x;
    y[num] = edges[i].y;
  }
  for (int i = 0; i < m; ++i) printf("%d %d\n", x[i] + 1, y[i] + 1);
  return 0;
}
