#include <bits/stdc++.h>
const int N = 300000;
using namespace std;
int n, m;
vector<pair<int, int> > costs, need;
set<pair<int, pair<int, int> > > F;
set<pair<int, pair<int, int> > >::iterator it;
pair<int, int> ans[N];
int bound[N];
void add_edge(int a, int b, pair<int, int> p) {
  ans[p.second] = make_pair(a, b);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int w, has;
    cin >> w >> has;
    w = 1e9 - w;
    if (has == 1) {
      costs.push_back(make_pair(w, i));
    } else
      need.push_back(make_pair(w, i));
  }
  sort(costs.begin(), costs.end());
  for (int i = 1; i < n; i++) {
    add_edge(i, i + 1, costs[i - 1]);
    bound[i] = costs[i - 1].first;
  }
  for (int i = n - 1; i >= 1; --i) {
    for (int j = i + 2; j <= n; j++) {
      F.insert(make_pair(bound[i], make_pair(i, j)));
      if (F.size() > 131131) break;
    }
  }
  sort(need.begin(), need.end());
  reverse(need.begin(), need.end());
  for (int i = 0; i < need.size(); i++) {
    pair<int, pair<int, int> > p = make_pair(need[i].first, make_pair(-1, -1));
    it = F.lower_bound(p);
    if (it == F.end()) {
      cout << -1 << endl;
      return 0;
    }
    p = (*it);
    F.erase(p);
    add_edge(p.second.first, p.second.second, need[i]);
  }
  for (int i = 1; i <= m; i++) {
    cout << ans[i].first << " " << ans[i].second << "\n";
  }
  return 0;
}
