#include <bits/stdc++.h>
using namespace std;
int answer[100005][2];
vector<pair<int, int> > edge;
int main() {
  int n, m, i, w, x, lft = 1, rgt = 3, st = 1;
  scanf("%d", &n);
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    scanf("%d", &w);
    scanf("%d", &x);
    edge.push_back(make_pair(w, i - 2 * i * x));
  }
  sort(edge.begin(), edge.end());
  for (i = 0; i < m; i++) {
    if (edge[i].second < 0) {
      answer[-edge[i].second][0] = st++;
      answer[-edge[i].second][1] = st;
      continue;
    }
    if (rgt > st) {
      printf("-1\n");
      return 0;
    }
    answer[edge[i].second][0] = lft;
    answer[edge[i].second][1] = rgt;
    if (lft == 1) {
      rgt++;
      lft = rgt - 2;
    } else
      lft--;
  }
  if (st != n) {
    cout << -1 << endl;
    return 0;
  }
  for (i = 1; i <= m; i++) printf("%d %d\n", answer[i][0], answer[i][1]);
  return 0;
}
