#include <bits/stdc++.h>
using namespace std;
int dx[8] = {-1, 1, 0, 0, 1, 1, -1, -1}, dy[8] = {0, 0, -1, 1, 1, -1, 1, -1};
char dc[4] = {'N', 'S', 'W', 'E'};
pair<int, int> ans[200005];
bool cmp(pair<pair<int, int>, int> p, pair<pair<int, int>, int> q) {
  if (p.first.first != q.first.first) return p.first.first < q.first.first;
  return p.first.second > q.first.second;
}
int main() {
  int n, m, en, w, p, x, y, f = 0, in;
  vector<pair<pair<int, int>, int> > v;
  cin >> n >> m;
  en = 1;
  for (int i = 1; i <= m; i++) {
    cin >> w >> p;
    v.push_back(make_pair(make_pair(w, p), i));
  }
  sort(v.begin(), v.end(), cmp);
  x = 1;
  y = 3;
  for (int i = 0; i < m; i++) {
    w = v[i].first.first;
    p = v[i].first.second;
    in = v[i].second;
    if (p == 1) {
      ans[in] = make_pair(en, en + 1);
      en++;
    } else {
      if (en < y) {
        f = 1;
        break;
      }
      if (y == x + 1 && en == y) {
        f = 1;
        break;
      } else if (y == x + 1) {
        y++;
        x = 1;
        ans[in] = make_pair(x, y);
        x++;
      } else {
        ans[in] = make_pair(x, y);
        x++;
      }
    }
  }
  if (f)
    cout << "-1\n";
  else {
    for (int i = 1; i <= m; i++)
      cout << ans[i].first << " " << ans[i].second << endl;
  }
}
