#include <bits/stdc++.h>
using namespace std;
const int PRIME = 1000 * 1000 * 1000 + 7;
const int MULTIPLIER = 523;
const int INFI = (1 << 30) - 1;
const long double INF = 2 * 1e9 + 1;
const long double EPS = 1e-9;
const long double PI = 3.141592653589793238462643383279502884L;
const int DIM = 2;
const int MAX = 100 * 1000;
pair<int, int> tree[MAX];
pair<int, int> other[MAX];
int len[MAX];
int treePos = 0;
int otherPos = 0;
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (m); ++i) {
    int a, b;
    cin >> a >> b;
    if (b) {
      tree[treePos++] = make_pair(a, i);
    } else {
      other[otherPos++] = make_pair(a, i);
    }
  }
  sort(tree, tree + treePos);
  sort(other, other + otherPos);
  vector<pair<int, pair<int, int>>> result;
  for (int i = 0; i < (treePos); ++i) {
    result.push_back(make_pair(tree[i].second, make_pair(0, i + 1)));
    len[i + 1] = tree[i].first;
  }
  int left = 1;
  int right = 2;
  bool ok = true;
  for (int i = 0; i < otherPos && ok; ++i) {
    int d = other[i].first;
    int number = other[i].second;
    if (len[right] > d) {
      ok = false;
      break;
    }
    if (left < 1) {
      ++right;
      left = right - 1;
    }
    if (len[right] > d) {
      ok = false;
      break;
    }
    if (right >= n) {
      ok = false;
    } else {
      result.push_back(make_pair(number, make_pair(left, right)));
      --left;
    }
  }
  if (!ok) {
    cout << "-1";
  } else {
    sort(result.begin(), result.end());
    for (int i = 0; i < ((int)(result).size()); ++i) {
      cout << result[i].second.first + 1 << " " << result[i].second.second + 1
           << "\n";
    }
  }
  return 0;
}
