#include <bits/stdc++.h>
using namespace std;
const int _N = 100010;
int n, m;
class E {
 public:
  int val, type, pla;
} s[_N];
inline bool operator<(const E &i, const E &j) {
  if (i.val == j.val) return i.type > j.type;
  return i.val < j.val;
}
pair<int, int> re[_N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++)
    scanf("%d%d", &s[i].val, &s[i].type), s[i].pla = i;
  sort(s + 1, s + m + 1);
  static pair<int, int> Queue[_N];
  static int L, R;
  for (int i = 1, j = 1; i <= m; i++)
    if (s[i].type) {
      re[s[i].pla] = make_pair(1, ++j);
      for (int k = 2; k < j && R <= m; k++) Queue[++R] = make_pair(j, k);
    } else {
      if (L == R) {
        printf("-1\n");
        return 0;
      }
      re[s[i].pla] = Queue[++L];
    }
  for (int i = 1; i <= m; i++) printf("%d %d\n", re[i].first, re[i].second);
  return 0;
}
