#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, l, r, c = 1;
vector<pair<pair<int, int>, int> > v;
pair<int, int> ans[100005];
int cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  if (a.first.first == b.first.first) return a.first.second > b.first.second;
  return a.first.first < b.first.first;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    v.push_back({{x, y}, i});
  }
  sort(v.begin(), v.end(), cmp);
  l = 1, r = 3;
  for (int i = 0; i < v.size(); i++)
    if (v[i].first.second)
      ans[v[i].second] = {1, ++c};
    else {
      l++;
      if (l == r) r++, l = 2;
      if (r > c) {
        cout << -1 << endl;
        return 0;
      }
      ans[v[i].second] = {l, r};
    }
  for (int i = 1; i <= m; i++)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
