#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<pair<pair<int, int>, int>> v;
pair<int, int> ans[N] = {};
int main() {
  ios::sync_with_stdio(0), ios_base::sync_with_stdio(0), cin.tie(0),
      cout.tie(0);
  ;
  int n, m, c, t;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> c >> t;
    v.push_back({{c, -t}, i});
  }
  sort(v.begin(), v.end());
  int l = 2, prv = 3, lprv = 2;
  for (auto u : v) {
    if (u.first.second != 0)
      ans[u.second] = {1, l}, ++l;
    else {
      if (prv >= l) return cout << -1 << "\n", 0;
      ans[u.second] = {prv, lprv};
      lprv--;
      if (lprv == 1) prv++, lprv = prv - 1;
    }
  }
  for (int i = 1; i <= m; ++i)
    cout << ans[i].first << " " << ans[i].second << '\n';
  return 0;
}
