#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
const int M = 255;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;
int n, m;
struct Node {
  int a, b, id;
  bool friend operator<(Node x, Node y) {
    if (x.a != y.a) return x.a < y.a;
    return -x.b < -y.b;
  }
} p[N + 10];
int ans[N + 10][2], lim = 2;
queue<pair<int, int> > que;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> p[i].a >> p[i].b;
    p[i].id = i;
  }
  sort(p + 1, p + 1 + m);
  for (int i = 1; i <= m; i++) {
    if (p[i].b) {
      ans[p[i].id][0] = 1;
      ans[p[i].id][1] = lim;
      for (int j = 2; j < lim; j++) {
        que.push(make_pair(j, lim));
        if ((int)que.size() >= N) break;
      }
      lim++;
    } else {
      if (que.empty()) {
        cout << -1;
        return 0;
      }
      pair<int, int> q = que.front();
      que.pop();
      ans[p[i].id][0] = q.first;
      ans[p[i].id][1] = q.second;
    }
  }
  for (int i = 1; i <= m; i++) cout << ans[i][0] << ' ' << ans[i][1] << "\n";
  return 0;
}
