#include <bits/stdc++.h>
using namespace std;
const int maxk = 20;
const int maxn = 1e5 + 17;
int N, M;
pair<pair<int, int>, int> edge[maxn];
int NN = 1;
int level[maxn];
pair<int, int> ans[maxn];
bool comp(pair<pair<int, int>, int> x, pair<pair<int, int>, int> y) {
  if (x.first.first < y.first.first) return true;
  if (x.first.first == y.first.first) return x.first.second > y.first.second;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N >> M;
  for (int i = 0; i < M; i++)
    cin >> edge[i].first.first >> edge[i].first.second, edge[i].second = i;
  sort(edge, edge + M, comp);
  for (int i = 1; i <= N; i++) level[i] = i;
  for (int i = 0; i < M; i++)
    if (edge[i].first.second)
      ans[edge[i].second] = {1, ++NN};
    else {
      bool ok = false;
      for (int j = 2; j <= NN; j++)
        if (level[j] < NN) {
          ok = true;
          ans[edge[i].second] = {j, ++level[j]};
          break;
        }
      if (!ok) return !printf("-1\n");
    }
  for (int i = 0; i < M; i++)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
