#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, int> > v;
vector<pair<pair<int, int>, int> > edges;
vector<long long> inc;
vector<pair<int, int> > rem;
pair<int, int> edg[100005];
int dist[100005];
int main() {
  int N, M;
  int w, inc;
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; i++) {
    scanf("%d%d", &w, &inc);
    v.push_back(pair<pair<int, int>, int>(pair<int, int>(w, inc), i));
  }
  sort(v.begin(), v.end());
  int j = 2;
  for (int i = 0; i < M; i++) {
    if (v[i].first.second) {
      dist[j++] = v[i].first.first;
      edg[v[i].second].first = 1;
      edg[v[i].second].second = j - 1;
    } else
      rem.push_back(pair<int, int>(v[i].first.first, v[i].second));
  }
  j = 1;
  int k = 3;
  for (int i = 0; i < rem.size(); i++) {
    int w = rem[i].first;
    int index = rem[i].second;
    j++;
    if (j == k) {
      j = 2;
      k++;
    }
    if (w < dist[k]) {
      printf("-1\n");
      return 0;
    }
    edg[index].first = j;
    edg[index].second = k;
  }
  for (int i = 0; i < M; i++) printf("%d %d\n", edg[i].first, edg[i].second);
  return 0;
}
