#include <bits/stdc++.h>
using namespace std;
int n, m;
struct M {
  int g, ok, id;
} Mu[100001];
pair<int, int> Ras[100001];
bool cmp(M x, M y) {
  if (x.g == y.g) return x.ok > y.ok;
  return x.g < y.g;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> Mu[i].g >> Mu[i].ok;
    Mu[i].id = i;
  }
  sort(Mu + 1, Mu + m + 1, cmp);
  int bun = 1, x = 1, y = 3;
  for (int i = 1; i <= m; ++i) {
    if (Mu[i].ok == 1) {
      Ras[Mu[i].id].first = bun;
      bun++;
      Ras[Mu[i].id].second = bun;
    } else {
      if (y > bun) {
        cout << -1;
        return 0;
      }
      Ras[Mu[i].id].first = x;
      x++;
      Ras[Mu[i].id].second = y;
      if (y - x == 1) {
        x = 1;
        y++;
      }
    }
  }
  for (int i = 1; i <= m; ++i)
    cout << Ras[i].first << ' ' << Ras[i].second << '\n';
}
