#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long n, m;
vector<pair<long long int, long long int>> ans(100005);
vector<pair<pair<long long int, long long int>, long long>> edg;
vector<vector<long long int>> adj(100005);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    cin >> n >> m;
    priority_queue<pair<long long int, long long int>,
                   vector<pair<long long int, long long int>>,
                   greater<pair<long long int, long long int>>>
        pq;
    for (long long int i = 0; i < m; i++) {
      long long w, b;
      cin >> w >> b;
      edg.push_back(make_pair(make_pair(w, (1 - b)), i));
    }
    for (long long int i = 1; i < n + 1; i++) {
      pq.push(make_pair(i + 2, i));
    }
    sort((edg).begin(), (edg).end());
    long long fl = 0, curr = 1;
    for (long long int i = 0; i < m; i++) {
      if (edg[i].first.second == 0) {
        ans[edg[i].second] = make_pair(curr, curr + 1);
        curr++;
      } else {
        pair<long long int, long long int> sel = pq.top();
        pq.pop();
        if (sel.first > curr) {
          fl = 1;
          break;
        }
        ans[edg[i].second] = make_pair(sel.second, sel.first);
        pq.push(make_pair(sel.first + 1, sel.second));
      }
    }
    if (fl == 1)
      cout << -1 << "\n";
    else {
      for (long long int i = 0; i < m; i++) {
        cout << ans[i].first << " " << ans[i].second << "\n";
      }
    }
  }
  return 0;
}
