#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
int n, m, nn, mm;
pair<int, int> a[100010], b[100010], ans[100010];
int solve() {
  int ind = 1;
  for (int i = nn; i--;) {
    ++ind;
    ans[a[i].second] = pair<int, int>(1, ind);
    int w = a[i].first;
    int id = lower_bound(b + 1, b + mm + 1, pair<int, int>(w, 0)) - b - 1;
    int Id = ind + 1;
    while (Id <= n && id < mm) {
      ans[b[mm].second] = pair<int, int>(ind, Id);
      Id++, mm--;
    }
  }
  if (mm) return puts("-1");
  for (int i = 1; i <= m; i++) printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int w, lo;
    scanf("%d%d", &w, &lo);
    if (lo)
      a[nn++] = pair<int, int>(w, i);
    else
      b[++mm] = pair<int, int>(w, i);
  }
  sort(a, a + nn);
  sort(b + 1, b + mm + 1);
  solve();
  return 0;
}
