#include <bits/stdc++.h>
using namespace std;
void read(int &n, int &m, vector<pair<int, int> > &u,
          vector<pair<int, int> > &unu) {
  int len, isUsed;
  scanf("%d%d", &n, &m);
  u.reserve(n - 1);
  unu.reserve(m - n + 1);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &len, &isUsed);
    if (isUsed)
      u.push_back(make_pair(i, len));
    else
      unu.push_back(make_pair(i, len));
  }
}
bool sortLess(const pair<int, int> &p1, const pair<int, int> &p2) {
  return p1.second < p2.second;
}
bool solve(vector<pair<int, int> > &u, vector<pair<int, int> > &unu,
           vector<pair<int, int> > &ans) {
  ans.resize(u.size() + unu.size());
  for (unsigned i = 0; i < u.size(); ++i) {
    ans[u[i].first].first = i + 1;
    ans[u[i].first].second = i + 2;
    u[i].first = i;
  }
  unsigned i = 0;
  for (unsigned j = 0; j < unu.size(); ++j) {
    while (i < u.size() && (u[i].first <= 0 || unu[j].second < u[i].second))
      ++i;
    if (i == u.size()) break;
    ans[unu[j].first].first = i - u[i].first + 1;
    ans[unu[j].first].second = i + 2;
    --u[i].first;
  }
  if (i == u.size()) return false;
  return true;
}
int main() {
  int n, m;
  vector<pair<int, int> > u, unu, ans;
  read(n, m, u, unu);
  sort(u.begin(), u.end(), sortLess);
  sort(unu.begin(), unu.end(), sortLess);
  if (solve(u, unu, ans))
    for (unsigned i = 0; i < ans.size(); ++i)
      printf("%d %d\n", ans[i].first, ans[i].second);
  else
    printf("-1");
  return 0;
}
