#include <bits/stdc++.h>
using namespace std;
int n, m, ans[100005][2];
pair<pair<int, int>, int> data[100005];
int main(int argc, char const *argv[]) {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> data[i].first.first >> data[i].first.second;
    data[i].first.second = -data[i].first.second;
    data[i].second = i;
  }
  sort(data, data + m);
  int a = 3, b = 2, c = 2;
  for (int i = 0; i < m; i++) {
    int tmp = data[i].second;
    if (data[i].first.second) {
      ans[tmp][0] = c++;
      ans[tmp][1] = 1;
    } else {
      if (a == b) {
        a++;
        b = 2;
      }
      if (a >= c) {
        cout << -1 << endl;
        return 0;
      }
      ans[tmp][0] = a;
      ans[tmp][1] = b++;
    }
  }
  for (int i = 0; i < m; i++) {
    cout << ans[i][0] << " " << ans[i][1] << endl;
  }
  return 0;
}
