#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 5;
const long long int mod = 1e9 + 7;
const long long int level = 20;
long long int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
long long int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
vector<pair<long long int, long long int> > u, v, ans;
int main() {
  ios::sync_with_stdio(false);
  long long int n, m;
  cin >> n >> m;
  bool y[m];
  ans.resize(m);
  for (long long int i = 0; i < m; i++) {
    long long int x;
    cin >> x >> y[i];
    if (y[i])
      v.push_back({x, i});
    else
      u.push_back({x, i});
  }
  sort(v.begin(), v.end());
  sort(u.begin(), u.end());
  bool possible = true;
  long long int it_v = 1;
  long long int it_times = 1;
  long long int cnt = 0;
  for (long long int i = 0; i < u.size(); i++) {
    if (u[i].first >= v[it_v].first)
      cnt++;
    else {
      possible = false;
      break;
    }
    if (cnt == it_times) it_times++, it_v++, cnt = 0;
  }
  if (!possible) {
    cout << "-1\n";
    return 0;
  }
  for (long long int i = 2; i < n + 1; i++) {
    ans[v[i - 2].second] = {i - 1, i};
  }
  long long int it = 1;
  long long int jt = 3;
  for (long long int i = 0; i < u.size(); i++) {
    ans[u[i].second] = {it, jt};
    it++;
    if ((jt - it) < 2) it = 1, jt++;
  }
  for (long long int i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
