#include <bits/stdc++.h>
using namespace std;
void FastIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  FastIO();
  int n, m, a, b, pos;
  cin >> n >> m;
  vector<pair<pair<int, int>, int> > V;
  for (int i = 0; i < (int)m; i++) {
    cin >> a >> b;
    V.push_back(make_pair(make_pair(a, -b), i));
  }
  sort((V).begin(), (V).end());
  if (V[0].first.second == 0 || (m > 1 && V[1].first.second == 0)) {
    cout << "-1" << '\n';
    return 0;
  }
  int last = 1;
  int first = 1;
  vector<int> next(n + 2, 0);
  for (int i = 1; i <= n; i++) {
    next[i] = i + 2;
  }
  vector<pair<int, int> > ans(m, pair<int, int>());
  for (int i = 0; i < (int)m; i++) {
    a = V[i].first.first;
    b = V[i].first.second;
    pos = V[i].second;
    if (b) {
      ans[pos] = make_pair(last, last + 1);
      last++;
      first = 1;
    } else {
      if (next[first] > last) {
        cout << "-1" << '\n';
        return 0;
      }
      ans[pos] = make_pair(first, next[first]);
      next[first]++;
      if (next[first] > last) first++;
    }
  }
  for (int i = 0; i < (int)m; i++) {
    cout << ans[i].first << " " << ans[i].second << '\n';
  }
  return 0;
}
