#include <bits/stdc++.h>
using namespace std;
const int N = 202000;
const int mod = 1e9 + 7;
const int inf = 2e9;
const long long infl = 2e18;
int n, m, a, b;
pair<int, pair<int, int> > g[N];
int c;
pair<int, int> res[N];
int edges;
pair<int, int> w[1000001];
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    b = 1 - b;
    g[c++] = make_pair(a, make_pair(b, i));
  }
  int cnt = 1;
  int sz = 0;
  sort(g, g + c);
  for (int i = 0; i < m; ++i) {
    if (g[i].second.first == 0) {
      res[g[i].second.second] = make_pair(1, ++cnt);
      edges++;
      if (edges <= m) {
        for (int j = 2; j < cnt; ++j) w[sz++] = make_pair(j, cnt), edges++;
      }
    } else {
      if (!sz) return cout << -1, 0;
      res[g[i].second.second] = w[--sz];
    }
  }
  for (int i = 0; i < m; ++i)
    cout << res[i].first << ' ' << res[i].second << "\n";
  return 0;
}
