#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
pair<pair<long long, long long>, long long> a[N];
pair<long long, long long> ans[N];
signed main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    cin >> a[i].first.first >> a[i].first.second;
    a[i].first.second ^= 1;
    a[i].second = i;
  }
  sort(a, a + m);
  long long cur = 1, nx = 1, nx2 = 3;
  for (long long i = 0; i < m; i++) {
    if (!a[i].first.second) {
      ans[a[i].second] = {cur, cur + 1};
      cur++;
      continue;
    }
    if (nx2 > cur) {
      puts("-1");
      return 0;
    }
    ans[a[i].second] = {nx, nx2};
    nx++;
    if (nx + 1 == nx2) {
      nx = 1;
      nx2++;
    }
  }
  for (long long i = 0; i < m; i++)
    cout << ans[i].first << " " << ans[i].second << "\n";
}
