#include <bits/stdc++.h>
using namespace std;
int chh;
const int N = 100005, INF = ~0U >> 2;
struct Node {
  int val, f, id;
  Node() {}
  Node(int A, int B, int C) : val(A), f(B), id(C) {}
  bool operator<(const Node &arg) const {
    if (val != arg.val) return val < arg.val;
    return f > arg.f;
  }
} p[N];
int n, m;
pair<int, int> res[N];
void gao(int &s, int &t) {
  if (s == t - 2)
    t++, s = 1;
  else
    s++;
}
int main() {
  int s, t, e, flag;
  while (~scanf("%d %d", &n, &m)) {
    for (int i = 0; i < (m); i++) {
      scanf("%d %d", &p[i].val, &p[i].f);
      p[i].id = i;
    }
    sort(p, p + m);
    if (p[0].f == 0) {
      puts("-1");
      continue;
    }
    e = 1, flag = 1, s = 1, t = 3;
    res[p[0].id] = make_pair(e, e + 1);
    e++;
    for (int i = (1); i <= (m - 1); i++) {
      if (p[i].f == 0) {
        if (t > e) {
          flag = 0;
          break;
        } else {
          res[p[i].id] = make_pair(s, t);
          gao(s, t);
        }
      } else {
        res[p[i].id] = make_pair(e, e + 1);
        e++;
      }
    }
    if (!flag)
      puts("-1");
    else {
      for (int i = 0; i < (m); i++)
        printf("%d %d\n", res[i].first, res[i].second);
    }
  }
  return 0;
}
