#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
int n, m;
pair<int, pair<int, int> > a[100010];
pair<int, int> g[100010];
int r[100010];
void solve() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i].first >> a[i].second.first;
    a[i].second.first *= -1;
    a[i].second.second = i;
  }
  for (int i = 0; i < n; i++) r[i] = i + 1;
  sort(a, a + m);
  int cur = 0;
  int lst = 0;
  for (int i = 0; i < m; i++) {
    if (a[i].second.first == -1) {
      cur = 1;
      lst++;
      g[a[i].second.second] = pair<int, int>(0, lst);
    } else {
      while (cur < lst && r[cur] > lst) cur++;
      if (cur >= lst) {
        cout << -1;
        return;
      }
      g[a[i].second.second] = pair<int, int>(cur, r[cur]);
      r[cur]++;
    }
  }
  for (int i = 0; i < m; i++) {
    cout << g[i].first + 1 << " " << g[i].second + 1 << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  srand(88);
  solve();
  return 0;
}
