#include <bits/stdc++.h>
using namespace std;
struct Node {
  long long w, flag, id;
  friend bool operator<(Node a, Node b) {
    if (a.w == b.w) return a.flag > b.flag;
    return a.w < b.w;
  }
};
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<Node> arr(m);
  for (long long i = 0; i < m; i++) {
    long long w, flag;
    cin >> w >> flag;
    arr[i] = {w, flag, i};
  }
  sort(arr.begin(), arr.end());
  bool tag = false;
  vector<pair<long long, long long>> ans(m + 1);
  long long x = 2, y = 3, now = 2;
  for (long long i = 0; i < m; i++) {
    if (arr[i].flag) {
      ans[arr[i].id] = make_pair(1, now);
      now++;
    } else {
      if (y >= now)
        tag = 1;
      else {
        ans[arr[i].id] = make_pair(x, y);
        x++;
        if (x == y) {
          y++;
          x = 2;
        }
      }
    }
  }
  if (tag) {
    cout << -1 << endl;
    return;
  }
  for (long long i = 0; i < m; i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
}
