#include <bits/stdc++.h>
using namespace std;
void rf() {}
const int nx[8] = {2, -2, -2, 2, 1, 1, -1, -1};
const int ny[8] = {1, 1, -1, -1, 2, -2, -2, 2};
const int Nx[4] = {0, 0, -1, 1};
const int Ny[4] = {1, -1, 0, 0};
const long long LINF = (long long)5e18;
const int INF = 1e9 + 7;
const int N = 2e5 + 123;
const int MAXN = 1e6 + 50;
const double EPS = 1e-9, PI = 3.14159265359;
inline int get_int() {
  char x = getchar();
  int ret = 0;
  bool neg = 0;
  while (!('0' <= x && x <= '9')) {
    if (x == '-') neg = 1;
    x = getchar();
  }
  while ('0' <= x && x <= '9') {
    ret = ret * 10 + x - '0';
    x = getchar();
  }
  if (neg) ret *= -1;
  return ret;
}
struct edge {
  int id, cost, used;
};
bool cmp(edge x, edge y) {
  if (x.cost != y.cost) return x.cost < y.cost;
  return x.used > y.used;
}
edge e[N];
int n, m;
pair<int, int> ans[N];
int main() {
  srand(time(0));
  rf();
  cin >> n >> m;
  int pt = 1;
  int mn = INF;
  vector<pair<int, int> > q;
  for (int i = 1; i <= m; i++) {
    cin >> e[i].cost >> e[i].used;
    e[i].id = i;
  }
  sort(e + 1, e + m + 1, cmp);
  for (int i = 1; i <= m; i++) {
    if (e[i].used) {
      pt++;
      for (int j = 2; j < pt && int(q.size()) < m; j++)
        q.push_back(make_pair(j, pt));
      ans[e[i].id] = make_pair(1, pt);
    } else {
      if (q.empty()) {
        cout << -1;
        return 0;
      }
      ans[e[i].id] = q.back();
      q.pop_back();
    }
  }
  for (int i = 1; i <= m; i++)
    cout << ans[i].first << ' ' << ans[i].second << "\n";
  return 0;
}
