#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > MST1, MST2;
int n, m;
int w, v;
pair<int, int> ans[1000005];
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> w >> v;
    if (v)
      MST1.push_back({w, i});
    else
      MST2.push_back({w, i});
  }
  sort(MST1.begin(), MST1.end());
  sort(MST2.begin(), MST2.end());
  reverse(MST1.begin(), MST1.end());
  reverse(MST2.begin(), MST2.end());
  for (int i = 0; i < MST1.size(); i++) ans[MST1[i].second] = {i + 1, i + 2};
  for (int i = 0, j = 0, k = 2; i < MST2.size(); i++) {
    while (j < n - 2 && MST1[j].first > MST2[i].first) j++, k = j + 2;
    if (j == n - 2) return 0 * puts("-1");
    ans[MST2[i].second] = {j + 1, k + 1};
    k++;
    if (k == n) j++, k = j + 2;
  }
  for (int i = 0; i < m; i++)
    cout << ans[i].first << ' ' << ans[i].second << '\n';
}
