#include <bits/stdc++.h>
using namespace std;
const int MX = 100005, infi = 1000000, mod = 998244353;
const double EPS = 1E-9;
int n, m, M = 1000000005, ok[MX], mx[MX];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  vector<pair<int, int> > A, second(MX);
  for (int i = 0; i < m; i++) {
    int w, is;
    cin >> w >> is;
    if (!is) is--;
    if (is) A.push_back({w, -1 * is * (i + 1)});
  }
  sort(A.begin(), A.end());
  for (int i = 2; i < MX; i++) mx[i] = i;
  int cnt = 2;
  vector<int> ready;
  for (int i = 0; i < m; i++) {
    if (A[i].second < 0) {
      if (cnt <= n) {
        second[abs(A[i].second)] = {1, cnt++};
        ready = {2};
      } else
        return cout << -1, 0;
    } else {
      if (cnt == 2) return cout << -1, 0;
      int X = ready.back();
      if (mx[X] >= cnt - 1) return cout << -1, 0;
      second[abs(A[i].second)] = {X, ++mx[X]};
      if (mx[X] == cnt - 1) ready.push_back(X + 1);
    }
  }
  for (int i = 1; i <= m; i++)
    cout << second[i].first << " " << second[i].second << "\n";
  return 0;
}
