#include <bits/stdc++.h>
using namespace std;
int mx, mn;
vector<pair<int, int> > tree, graph;
int ans[110000][2];
int main() {
  int i, j, k, l, z;
  int n, m;
  cin >> n >> m;
  mx = -1, mn = 1e9;
  int cnt = 1;
  int par, chil;
  for (i = 0; i < m; i++) {
    cin >> k >> l;
    if (l)
      tree.push_back({k, i});
    else
      graph.push_back({k, i});
  }
  sort(tree.begin(), tree.end());
  sort(graph.begin(), graph.end());
  for (i = 0; i < n - 1; i++) {
    k = tree[i].second;
    ans[k][0] = i + 1;
    ans[k][1] = i + 2;
  }
  l = 0;
  int flag = 0;
  for (i = 2; i < n; i++) {
    mn = tree[i - 1].first;
    for (j = i - 2; j >= 0; j--, l++) {
      if (l >= (int)graph.size()) break;
      k = graph[l].first;
      if (k < mn) flag = 1;
      z = graph[l].second;
      ans[z][0] = j + 1;
      ans[z][1] = i + 1;
    }
  }
  if (flag) {
    cout << -1;
    return 0;
  } else {
    for (i = 0; i < m; i++) {
      cout << ans[i][0] << ' ' << ans[i][1] << '\n';
    }
  }
}
