#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  long long n, m;
  cin >> n >> m;
  pair<pair<long long, long long>, long long> edges[m];
  for (long long i = 0; i < m; i++) {
    long long w, c;
    cin >> w >> c;
    edges[i] = {{w, 1 - c}, i};
  }
  pair<long long, long long> ans[m];
  long long count[n + 1];
  for (long long j = 3; j <= n; j++) count[j] = j - 2;
  sort(edges, edges + m);
  long long s = 1, ok = 1, u = 3;
  for (long long i = 0; i < m; i++) {
    long long idx = edges[i].second;
    edges[i].first.second ^= 1;
    long long v = s;
    long long e = i;
    if (edges[i].first.second == 0) {
      long long te = v * (v - 1) / 2;
      if (e == te) {
        ok = 0;
        break;
      }
      if (count[u] == 0) u++;
      ans[idx] = {u - count[u], u};
      count[u]--;
    } else {
      ans[idx] = {1, s + 1};
      s++;
    }
  }
  if (ok) {
    for (long long i = 0; i < m; i++)
      cout << ans[i].first << " " << ans[i].second << '\n';
  } else {
    cout << "-1";
  }
}
