#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<array<int, 3>> E(m);
  vector<array<int, 2>> ats(m);
  vector<int> sz(n + 1);
  vector<int> D = {-1, 0};
  for (int i = 0; i < m; i++) {
    cin >> E[i][0] >> E[i][1], E[i][1] ^= 1, E[i][2] = i;
    if (E[i][1] == 0) D.push_back(E[i][0]);
  }
  sort(E.begin(), E.end());
  sort(D.begin(), D.end());
  if (E[0][1]) return cout << -1, 0;
  ats[E[0][2]] = {1, 2};
  int nxt = 3;
  int cur = 2;
  for (int i = 1; i < m; i++)
    if (!E[i][1])
      ats[E[i][2]] = {1, nxt++};
    else {
      int u = 2;
      while (u < nxt && sz[u] == nxt - u - 1) u++;
      if (u + sz[u] + 1 >= nxt) return cout << -1, 0;
      ats[E[i][2]] = {u, u + sz[u] + 1};
      sz[u]++;
    }
  for (int i = 0; i < m; i++) cout << ats[i][0] << " " << ats[i][1] << "\n";
}
