#include <bits/stdc++.h>
using namespace std;
string itos(int x) {
  stringstream ss;
  ss << x;
  return ss.str();
}
int n, m;
pair<pair<int, int>, int> a[100010];
int sz = 1;
bool f;
pair<int, int> out[100010];
priority_queue<pair<int, int> > pq;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; a[i].first.second ^= 1, a[i].second = i, i++)
    cin >> a[i].first.first >> a[i].first.second;
  sort(a, a + m);
  for (int i = 0; i < m; i++) {
    if (!a[i].first.second) {
      out[a[i].second] = make_pair((1), (++sz));
      pq.push(make_pair((-(sz + 1)), (sz)));
    } else {
      if (sz == 1) {
        cout << -1 << endl;
        return 0;
      }
      pair<int, int> best = pq.top();
      pq.pop();
      if (-best.first > sz) {
        cout << -1 << endl;
        return 0;
      }
      out[a[i].second] = make_pair((-best.first), (best.second));
      --best.first;
      pq.push(best);
    }
  }
  for (int i = 0; i < m; i++)
    cout << out[i].first << ' ' << out[i].second << endl;
  return 0;
}
