#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const long long int mod = 1e9 + 7;
const int MAXN = 1e6 + 5;
struct edge {
  int wt, was_included, idx;
  edge() {}
  edge(int wt, int was_included, int idx)
      : wt(wt), was_included(was_included), idx(idx) {}
  const bool operator<(const edge &e) const {
    if (wt != e.wt)
      return wt < e.wt;
    else
      return was_included > e.was_included;
  }
};
void cp() {
  int n, m;
  cin >> n >> m;
  vector<edge> edges;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    edges.push_back(edge(a, b, i));
  }
  sort(edges.begin(), edges.end());
  int u = 2;
  queue<pair<int, int> > allowed;
  vector<pair<int, int> > ans(m);
  bool ok = true;
  for (edge e : edges) {
    if (e.was_included) {
      ans[e.idx] = {1, u};
      if (u > 2) allowed.push({2, u});
      u++;
    } else {
      if (!allowed.empty()) {
        pair<int, int> avail = allowed.front();
        allowed.pop();
        ans[e.idx] = avail;
        avail.first++;
        if (avail.first < avail.second) allowed.push(avail);
      } else
        ok = false;
    }
  }
  if (ok) {
    for (auto x : ans) cout << x.first << " " << x.second << '\n';
  } else
    cout << -1 << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  t = 1;
  while (t--) {
    cp();
  }
  return 0;
}
