#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, int> > vec;
vector<pair<int, int> > edge;
vector<pair<int, int> > pos;
int main() {
  int n, m, i;
  scanf("%d %d", &n, &m);
  for (i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    y ^= 1;
    vec.push_back(make_pair(make_pair(x, y), i));
    edge.push_back(make_pair(0, 0));
  }
  sort(vec.begin(), vec.end());
  int x_l = 1, y_l = 2;
  int x = 1;
  int j;
  for (i = 0, j = 0; i < m; i++) {
    if (vec[i].first.second == 0) {
      int idx = vec[i].second;
      edge[idx].first = x++;
      edge[idx].second = x;
      int y = 1;
      while (y + 2 <= x && int(pos.size()) < m) {
        pos.push_back(make_pair(y, x));
        y++;
      }
    } else {
      int idx = vec[i].second;
      if (j >= int(pos.size())) {
        printf("-1\n");
        return 0;
      }
      edge[idx] = pos[j];
      j++;
    }
  }
  for (i = 0; i < m; i++) {
    if (edge[i].first == 0 || edge[i].second == 0) return -1;
    printf("%d %d\n", edge[i].first, edge[i].second);
  }
  return 0;
}
