#include <bits/stdc++.h>
using namespace std;
pair<pair<int, int>, int> e[100005];
pair<int, int> gr[100005];
vector<int> M[100005];
bool comp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  if (a.first.first != b.first.first)
    return a.first.first < b.first.first;
  else if (a.first.second == 1 && b.first.second == 1)
    return a.second < b.second;
  else if (a.first.second == 1)
    return 1;
  else if (b.first.second == 1)
    return 0;
  else
    return a.second < b.second;
}
int main() {
  int i, n, m;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> e[i].first.first >> e[i].first.second;
    e[i].second = i;
  }
  sort(e, e + m, comp);
  int cur = 1, j;
  int st = 3;
  for (i = 3; i <= n; i++) {
    M[i].push_back(i - 2);
  }
  bool first = 0;
  for (i = 0; i < m; i++) {
    if (e[i].first.second == 1) {
      gr[e[i].second] = pair<int, int>(cur, cur + 1);
      cur++;
    } else {
      if (st > cur) {
        first = 1;
        break;
      } else {
        int u = st;
        int v = M[st][M[st].size() - 1];
        gr[e[i].second] = pair<int, int>(u, v);
        M[st].pop_back();
        if (u < n) M[u + 1].push_back(v);
        if (M[st].size() == 0) st++;
      }
    }
  }
  if (first == 1) {
    printf("-1\n");
    return 0;
  }
  for (i = 0; i < m; i++) {
    printf("%d %d\n", gr[i].first, gr[i].second);
  }
}
