#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long n, m;
    cin >> n >> m;
    vector<pair<pair<long long int, long long int>, long long> > a(m);
    for (long long int i = 0; i < m; i++)
      cin >> a[i].first.first >> a[i].first.second;
    for (long long int i = 0; i < m; i++)
      a[i].second = i, a[i].first.second = -a[i].first.second;
    sort((a).begin(), (a).end());
    long long st = 2, end = 3, mx = 2;
    vector<pair<long long int, long long int> > ans(m);
    for (long long int i = 0; i < m; i++) {
      if (a[i].first.second == -1) {
        ans[a[i].second] = make_pair(1, mx);
        mx++;
      } else {
        if (st == 1) {
          end++;
          st = end - 1;
        }
        if (end >= mx) {
          cout << -1;
          return 0;
        }
        ans[a[i].second] = make_pair(st, end);
        st--;
      }
    }
    for (long long int i = 0; i < m; i++)
      cout << ans[i].first << " " << ans[i].second << '\n';
  }
  return 0;
}
