#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<pair<int, int>, int> > input;
vector<pair<int, pair<int, int> > > output;
set<pair<int, int> > edges;
int main() {
  scanf("%d %d", &n, &m);
  input.resize(m);
  for (int i = 0; i < (int)(m); i++) {
    scanf("%d %d", &input[i].first.first, &input[i].first.second);
    input[i].second = i;
    input[i].first.second *= -1;
  }
  sort(input.begin(), input.end());
  int comp = 1;
  edges.clear();
  output.clear();
  for (int i = 0; i < (int)(m); i++) {
    if (input[i].first.second == 0 && edges.empty()) {
      cout << -1 << endl;
      return 0;
    } else if (input[i].first.second == 0) {
      output.push_back(make_pair(input[i].second, *edges.begin()));
      edges.erase(edges.begin());
    } else {
      if (edges.size() < m - i + 1) {
        for (int j = 1; j < comp; j++) edges.insert(make_pair(j, comp));
      }
      output.push_back(make_pair(input[i].second, make_pair(0, comp)));
      comp++;
    }
  }
  sort(output.begin(), output.end());
  for (int i = 0; i < (int)(m); i++)
    printf("%d %d\n", output[i].second.first + 1, output[i].second.second + 1);
}
