#include <bits/stdc++.h>
using namespace std;
const int MAX = 100020;
struct Edge {
  int id, len;
  bool used;
  Edge() {}
  Edge(int id, int len, bool used) : id(id), len(len), used(used) {}
};
bool compareLen(const Edge &f, const Edge &s) {
  if (f.len == s.len) return f.used > s.used;
  return f.len < s.len;
}
int n, m;
Edge edge[MAX];
void input() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int len, used;
    scanf("%d%d", &len, &used);
    edge[i] = Edge(i, len, used);
  }
  sort(edge, edge + m, compareLen);
}
int from[MAX], to[MAX];
bool solve() {
  int last = 1, now = 3, remain = 1;
  for (int i = 0; i < m; i++) {
    Edge &cur = edge[i];
    if (cur.used) {
      from[cur.id] = last;
      to[cur.id] = last + 1;
      last++;
    } else {
      if (last < now) return 0;
      from[cur.id] = now;
      to[cur.id] = remain;
      remain--;
      if (remain == 0) {
        now++;
        remain = now - 2;
      }
    }
  }
  return 1;
}
void print() {
  for (int i = 0; i < m; i++) printf("%d %d\n", from[i], to[i]);
}
int main() {
  input();
  if (solve())
    print();
  else
    puts("-1");
  return 0;
}
