#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<pair<pair<int, int>, int> > edges;
vector<pair<int, pair<int, int> > > ans;
vector<pair<int, int> > extra;
int n, idx, m;
int main() {
  int e = 2, idx = 0;
  scanf("%d %d", &n, &m);
  for (int i = int(3); i <= int(N); i++) {
    for (int j = int(i - 1); j >= 0; j--) {
      extra.push_back(make_pair(i, j));
      if (j == 2) break;
      if (int(extra.size()) == N) break;
    }
    if (int(extra.size()) == N) break;
  }
  for (int i = 0; i < int(m); i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    edges.push_back(make_pair(make_pair(a, 1 - b), i));
  }
  sort(edges.begin(), edges.end());
  for (int i = 0; i < int(m); i++) {
    if (edges[i].first.second) {
      if (extra[idx].first >= e) return puts("-1");
      ans.push_back(make_pair(edges[i].second, extra[idx++]));
    } else {
      ans.push_back(make_pair(edges[i].second, make_pair(1, e++)));
    }
  }
  sort(ans.begin(), ans.end());
  for (int i = 0; i < int(m); i++) {
    printf("%d %d\n", ans[i].second.first, ans[i].second.second);
  }
  return 0;
}
