#include <bits/stdc++.h>
using namespace std;
int nx[100010];
struct node {
  int first, second, p;
} ar[100010], ed[100010];
class compare {
 public:
  bool operator()(node x, node y) {
    if (x.second == y.second)
      return x.first < y.first;
    else
      return x.second < y.second;
  }
};
int val[100010];
int main() {
  ios::sync_with_stdio(false);
  for (int i = 1; i <= 100005; i++) nx[i] = 1;
  int i, j, x, y, n, m, a, b, c = 0, p = 2, d = 0;
  cin >> n >> m;
  for (int i = 0; i <= m - 1; i++) {
    cin >> a >> b;
    if (b == 0)
      b = 1;
    else
      b = 0;
    ar[i].first = a;
    ar[i].second = b;
    ar[i].p = i;
    if (ar[i].second == 0) c++;
  }
  sort(ar, ar + m, compare());
  if (c != n - 1) {
    cout << -1 << '\n';
    return 0;
  }
  for (int i = 0; i <= n - 2; i++) {
    val[p] = ar[i].first;
    a = ar[i].p;
    ed[a].first = p;
    ed[a].second = p - 1;
    p++;
  }
  p = 3;
  for (int i = n - 1; i <= m - 1; i++) {
    while (p - nx[p] <= 1) {
      p++;
    }
    if (val[p] > ar[i].first) d = 1;
    a = ar[i].p;
    ed[a].first = p;
    ed[a].second = nx[p];
    nx[p]++;
  }
  if (d == 1)
    cout << -1 << '\n';
  else {
    for (int i = 0; i <= m - 1; i++)
      cout << ed[i].first << ' ' << ed[i].second << '\n';
  }
  return 0;
}
