#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 19;
pair<pair<int, int>, int> v[N];
long long aa[N], bb[N];
long long ans, sum;
long long n, m;
map<pair<int, int>, bool> edge;
int j = 0, k = 1, l = 2, s = 1;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> v[i].first.first >> v[i].first.second;
    v[i].first.second ^= 1;
    v[i].second = i;
  }
  sort(v, v + m);
  for (int i = 0; i < m; i++) {
    int jj = v[i].first.second;
    int loc = v[i].second;
    if (jj == 0) {
      aa[loc] = j, bb[loc] = k;
      k++;
    } else {
      while (edge[{s, l}] == 1) {
        if (s < l - 1) {
          s++;
        } else {
          l++;
          s = 1;
        }
      }
      if (l >= k) {
        cout << -1 << endl;
        return 0;
      }
      aa[loc] = s;
      bb[loc] = l;
      edge[make_pair(s, l)] = 1;
    }
  }
  for (int i = 0; i < m; i++) {
    cout << aa[i] + 1 << " " << bb[i] + 1 << endl;
  }
  return 0;
}
