#include <bits/stdc++.h>
using namespace std;
const int N = (int)(1e5) + 7;
const int M = (int)(1e5) + 7;
const int BLOCK_SIZE = 320;
const long double eps = 1e-12;
const long long INF = (long long)(1e9) + 7;
const long long MOD = (long long)(1e9) + 7;
vector<pair<pair<int, int>, int> > ls;
vector<int> ver_add, ver_n;
vector<pair<int, int> > pr;
pair<int, int> res[N];
bool cmp(pair<pair<int, int>, int> first, pair<pair<int, int>, int> second) {
  return (first.first.first < second.first.first ||
          (first.first.first == second.first.first &&
           first.first.second > second.first.second));
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int w, b;
    cin >> w >> b;
    ls.push_back(make_pair(make_pair(w, b), i));
  }
  for (int i = 1; i < n; ++i) ver_n.push_back(i);
  ver_add.push_back(0);
  sort(ls.begin(), ls.end(), cmp);
  int count = 0, cnt_n = 0;
  for (int i = 0; i < m; ++i) {
    int w = ls[i].first.first, b = ls[i].first.second, num = ls[i].second;
    if (b) {
      int v = ver_n[cnt_n];
      ++cnt_n;
      res[num] = make_pair(1, v + 1);
      for (int i = 1; i < (int)(ver_add.size()) && ((int)pr.size()) < N; ++i) {
        pr.push_back(make_pair(ver_add[i] + 1, v + 1));
      }
      ver_add.push_back(v);
    } else {
      if (count >= (int)(pr.size())) {
        return cout << -1 << endl, 0;
      }
      res[num] = pr[count];
      ++count;
    }
  }
  for (int i = 0; i < m; ++i)
    cout << res[i].first << ' ' << res[i].second << endl;
  return 0;
}
