#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int n, m;
struct Edge {
  int id, w, in;
  void read() { scanf("%d%d", &w, &in); }
  bool operator<(const Edge& e) const {
    return w < e.w || (w == e.w && in > e.in);
  }
};
Edge edges[maxn];
pair<int, int> ans[maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    edges[i].id = i;
    edges[i].read();
  }
  sort(edges + 1, edges + 1 + m);
  int s = 1, t = 3;
  int cnt = 0, available = 0;
  for (int i = 1; i <= m; i++) {
    int id = edges[i].id;
    if (edges[i].in == 1) {
      cnt++;
      available += cnt;
      ans[id] = make_pair(cnt, cnt + 1);
    } else {
      if (available == 0) {
        printf("-1\n");
        return 0;
      } else {
        ans[id] = make_pair(s, t);
        s++;
        if (t == s + 1) {
          t++;
          s = 1;
        }
      }
    }
    available--;
  }
  for (int i = 1; i <= m; i++) printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
