#include <bits/stdc++.h>
using namespace std;
pair<int, pair<bool, int> > edj[100010];
vector<pair<int, int> > ans;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> edj[i].first >> edj[i].second.first;
    edj[i].second.second = i;
    edj[i].second.first ^= 1;
  }
  sort(edj, edj + m);
  set<pair<int, int> > q;
  vector<int> cmp;
  cmp.push_back(1);
  int curr_node = 2;
  ans.resize(m);
  for (int i = 0, u, v; i < m; ++i) {
    if (!edj[i].second.first) {
      u = 1;
      v = curr_node;
      cmp.push_back(curr_node++);
      q.insert(make_pair(v + 1, v));
    } else {
      if (q.empty() || curr_node == q.begin()->first) {
        cout << "-1";
        return 0;
      }
      u = q.begin()->second;
      v = q.begin()->first;
      q.erase(q.begin());
      q.insert(make_pair(v + 1, u));
    }
    ans[edj[i].second.second] = make_pair(u, v);
  }
  for (int i = 0; i < m; ++i) {
    cout << ans[i].first << " " << ans[i].second << '\n';
  }
}
