#include <bits/stdc++.h>
using namespace std;
const int MAXn = 100 * 1000;
pair<pair<int, int>, int> w[MAXn + 5];
pair<int, int> ans[MAXn + 5];
int last[MAXn + 5];
bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  if (a.first.first < b.first.first)
    return true;
  else if (a.first.first == b.first.first && a.first.second > b.first.second)
    return true;
  return false;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &w[i].first.first, &w[i].first.second);
    w[i].second = i + 1;
  }
  sort(w, w + m, cmp);
  int size = 0;
  bool poss = true;
  for (int i = 0; i < n; i++) last[i] = -1;
  for (int i = 0; i < m && poss; i++) {
    if (w[i].first.second) {
      ans[w[i].second] = make_pair(size + 1, size + 2);
      size++;
    } else {
      poss = false;
      for (int j = 0; j <= size && !poss; j++)
        for (int k = last[j] + 1; k <= size && !poss; k++)
          if (j != k && j + 1 != k && j - 1 != k) {
            ans[w[i].second] = make_pair(j + 1, k + 1);
            last[j] = k;
            last[k] = j;
            poss = true;
          }
    }
  }
  if (!poss)
    cout << -1 << endl;
  else
    for (int i = 1; i <= m; i++) printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
