#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18 + 9;
const int inf = 1e9 + 9;
const int N = 1e5 + 9;
vector<pair<int, pair<int, int> > > temp;
pair<int, int> ans[N];
int n, m, w, ww;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> w >> ww;
    temp.push_back(make_pair(w, make_pair(!ww, i)));
  }
  sort(temp.begin(), temp.end());
  int node = 1;
  int t1 = 1;
  int t2 = 2;
  int tt = 1, tt2 = 0;
  int last = inf;
  bool flag = false;
  for (int i = 0; i < temp.size(); i++) {
    if (temp[i].second.first) {
      if (t2 == t1 + 1) t2++, t1 = 1;
      if (t2 > node) {
        cout << -1 << endl;
        return 0;
      }
      ans[temp[i].second.second] = make_pair(t1, t2);
      t1++;
    } else {
      ans[temp[i].second.second] = make_pair(node, node + 1);
      node++;
    }
    last = temp[i].first;
  }
  for (int i = 1; i <= m; i++)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
