#include <bits/stdc++.h>
using namespace std;
const int MAXN = 0;
bool possible = true;
int N, M, cur = 1, cur2 = 3, cur3 = 1;
vector<pair<pair<int, int>, int> > E;
vector<pair<int, pair<int, int> > > ans;
int main() {
  scanf("%d", &N), scanf("%d", &M);
  for (int i = 0; i < (int)M; i++) {
    int w, in;
    scanf("%d", &w), scanf("%d", &in);
    E.push_back({{w, 1 - in}, i});
  }
  sort(E.begin(), E.end());
  for (int i = 0; i < (int)M; i++) {
    int w = E[i].first.first;
    int out = E[i].first.second;
    int pos = E[i].second;
    if (!out) {
      ans.push_back({pos, {cur, cur + 1}});
      cur++;
    } else {
      if (cur2 > cur) possible = false;
      ans.push_back({pos, {cur2, cur3}});
      cur3++;
      if (cur3 == cur2 - 1) cur2++, cur3 = 1;
    }
  }
  sort(ans.begin(), ans.end());
  if (possible)
    for (int i = 0; i < (int)ans.size(); i++)
      printf("%d %d\n", ans[i].second.first, ans[i].second.second);
  else
    printf("-1\n");
}
