#include <bits/stdc++.h>
using namespace std;
int n, m;
int last = 1;
int ls = 1;
int p = 2;
pair<pair<int, int>, int> in[100005];
pair<int, int> ans[100005];
bool cmp(pair<pair<int, int>, int> p1, pair<pair<int, int>, int> p2) {
  if (p1.first.first == p2.first.first)
    return p1.first.second > p2.first.second;
  return p1.first.first < p2.first.first;
}
vector<pair<int, int> > vec;
int main() {
  scanf("%d", &n), scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d", &a), scanf("%d", &b);
    in[i] = {{a, b}, i};
  }
  int cnt = m - (n - 1);
  for (int i = 3; i <= n && cnt; ++i) {
    for (int j = 1; j < i - 1 && cnt; ++j) {
      cnt--;
      vec.push_back({j, i});
    }
  }
  sort(in, in + m, cmp);
  int idx = 0;
  for (int i = 0; i < m; ++i) {
    if (in[i].first.second == 0) {
      if (idx >= vec.size() || vec[idx].first > last || vec[idx].second > last)
        return cout << -1, 0;
      ans[in[i].second] = (vec[idx++]);
    } else
      ans[in[i].second] = {last, last + 1}, last++;
  }
  for (int i = 0; i < m; ++i) printf("%d %d\n", ans[i].first, ans[i].second);
}
