#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int a;
  int b;
  int id;
  bool operator<(const Edge& other) const {
    return (a < other.a || (a == other.a && b > other.b));
  }
};
Edge e[100005];
pair<int, int> ans[100005];
int main() {
  int n, m;
  int a, b;
  while (cin >> n >> m) {
    for (int i = 0; i < m; i++) {
      scanf("%d %d", &a, &b);
      e[i].a = a;
      e[i].b = b;
      e[i].id = i;
    }
    sort(e, e + m);
    int top = 1;
    int zero = 0;
    int one, two;
    one = 3;
    two = 2;
    bool flag = 0;
    for (int i = 0; i < m; i++) {
      int b = e[i].b;
      if (b == 1) {
        top++;
        ans[e[i].id] = make_pair(1, top);
      } else {
        zero++;
        if ((long long)top * (top - 1) / 2 >= top - 1 + zero) {
          ans[e[i].id] = make_pair(one, two);
          if (two + 1 == one) {
            one++;
            two = 2;
          } else {
            two++;
          }
        } else {
          flag = 1;
          break;
        }
      }
    }
    if (flag) {
      puts("-1");
    } else {
      for (int i = 0; i < m; i++) {
        printf("%d %d\n", ans[i].first, ans[i].second);
      }
    }
  }
  return 0;
}
