#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  std::vector<pair<int, int> > v(m);
  std::vector<pair<int, int> > ans(m);
  std::vector<pair<int, int> > min_tree(n - 1);
  std::vector<pair<int, int> > remain(m - n + 1);
  int x, y;
  int j = 0, k = 0;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    v[i] = make_pair(x, y);
    if (y == 1) {
      min_tree[j] = make_pair(x, i);
      j++;
    } else {
      remain[k] = make_pair(x, i);
      k++;
    }
  }
  sort(min_tree.begin(), min_tree.end());
  sort(remain.begin(), remain.end());
  bool b = true;
  int start = 2;
  std::vector<int> minvalue(n + 1);
  for (int i = 0; i <= n; i++) minvalue[i] = -1;
  for (int i = 0; i < n - 1; i++) {
    ans[min_tree[i].second] = make_pair(1, start);
    minvalue[start] = min_tree[i].first;
    start++;
  }
  start = 2;
  int end = 3;
  for (int i = 0; i < m - n + 1; i++) {
    if (minvalue[end] > remain[i].first) b = false;
    ans[remain[i].second] = make_pair(start, end);
    start++;
    if (start >= end) {
      start = 2;
      end++;
    }
  }
  if (!b) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 0; i < m; i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
}
