#include <bits/stdc++.h>
using namespace std;
pair<int, pair<int, int> > a[100000];
pair<int, int> ans[100000];
int to[100001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int w, p;
    cin >> w >> p;
    a[i] = make_pair(w, make_pair(!p, i));
  }
  sort(a, a + m);
  for (int i = 0; i <= n; i++) to[i] = i;
  int use = 1;
  int from = 2;
  for (int i = 0; i < m; i++) {
    if (a[i].second.first == 0) {
      ans[a[i].second.second] = make_pair(1, use + 1);
      use++;
    } else {
      if (to[from] + 1 > use) {
        from++;
        if (to[from] + 1 > use) {
          from = 2;
          if (to[from] + 1 > use) {
            cout << -1;
            return 0;
          } else {
            to[from]++;
          }
        } else {
          to[from]++;
        }
      } else {
        to[from]++;
      }
      ans[a[i].second.second] = make_pair(from, to[from]);
    }
  }
  for (int i = 0; i < m; i++)
    cout << ans[i].first << " " << ans[i].second << "\n";
  return 0;
}
