#include <bits/stdc++.h>
using namespace std;
FILE *in;
FILE *out;
const int MAX = 131072;
struct Subinterval {
  int left, right, price;
  Subinterval(int left_ = 0, int right_ = 0, int price_ = 0)
      : left(left_), right(right_), price(price_) {}
  bool operator<(const Subinterval r) const { return price > r.price; }
};
int n, m;
int nxt[MAX];
int ans[MAX][2];
vector<pair<int, int> > use, dont;
int main(void) {
  in = stdin;
  out = stdout;
  fscanf(in, "%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int price, used;
    fscanf(in, "%d %d", &price, &used);
    if (used)
      use.push_back(make_pair(price, i));
    else
      dont.push_back(make_pair(price, i));
  }
  sort(use.begin(), use.end());
  sort(dont.begin(), dont.end());
  for (int i = 0; i < (int)use.size(); i++) {
    ans[use[i].second][0] = i;
    ans[use[i].second][1] = i + 1;
  }
  priority_queue<pair<int, int> > q;
  for (int idx = 0; idx + 2 < n; idx++) {
    nxt[idx] = idx + 2;
    q.push(make_pair(-use[nxt[idx] - 1].first, idx));
  }
  for (int i = 0; i < (int)dont.size(); i++) {
    if (q.empty() || dont[i].first < -q.top().first) {
      fprintf(out, "-1\n");
      return 0;
    }
    int idx = q.top().second;
    q.pop();
    ans[dont[i].second][0] = idx;
    ans[dont[i].second][1] = nxt[idx]++;
    if (nxt[idx] < n) {
      q.push(make_pair(-use[nxt[idx] - 1].first, idx));
    }
  }
  for (int i = 0; i < m; i++)
    fprintf(out, "%d %d\n", ans[i][0] + 1, ans[i][1] + 1);
  return 0;
}
