#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> x, y;
  for (int i = 0; i < m; ++i) {
    int f, g;
    cin >> f >> g;
    if (g) {
      x.emplace_back(f, i);
    } else {
      y.emplace_back(f, i);
    }
  }
  vector<pair<int, int>> ans(m);
  sort((x).begin(), (x).end());
  m -= (int)x.size();
  sort((y).begin(), (y).end());
  reverse((y).begin(), (y).end());
  int now = 1;
  for (auto [f, i] : x) {
    ans[i] = {now, now + 1};
    ++now;
  }
  for (int j = 0; j <= x.size(); ++j) {
    for (int i = 0; i + 2 <= j && !y.empty(); ++i) {
      if (x[j - 1].first > y.back().first) {
        cout << -1;
        return 0;
      } else {
        ans[y.back().second] = {i + 1, j + 1};
        y.pop_back();
      }
    }
  }
  if (!y.empty()) {
    cout << -1;
    return 0;
  }
  m += x.size();
  for (int i = 0; i < m; ++i) {
    cout << ans[i].first << " " << ans[i].second << '\n';
  }
}
