#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, int> > e;
pair<int, int> ans[100010];
int main() {
  ios::sync_with_stdio(false);
  int n, m, p1 = 1, p2 = 3, p3 = 1;
  cin >> n >> m;
  for (int i = 1, u, v; i <= m; i++) cin >> u >> v, e.push_back({{u, -v}, i});
  sort(e.begin(), e.end());
  for (auto x : e) {
    if (x.first.second == -1)
      ans[x.second] = {p1, p1 + 1}, p1++;
    else {
      if (!p3) p2++, p3 = p2 - 2;
      if (p2 > p1) {
        cout << -1;
        return 0;
      }
      ans[x.second] = {p2, p3}, p3--;
    }
  }
  for (int i = 1; i <= m; i++)
    cout << ans[i].first << ' ' << ans[i].second << endl;
  return 0;
}
