#include <bits/stdc++.h>
const double eps = (1e-10);
using namespace std;
int dcmp(double a, double b) {
  return fabs(a - b) <= eps ? 0 : (a > b) ? 1 : -1;
}
long long getBit(long long num, int idx) { return ((num >> idx) & 1ll) == 1ll; }
long long setBit1(long long num, int idx) { return num | (1ll << idx); }
long long setBit0(long long num, int idx) { return num & ~(1ll << idx); }
long long flipBit(long long num, int idx) { return num ^ (1ll << idx); }
int countNumBit1(long long mask) {
  int ret = 0;
  while (mask) {
    mask &= (mask - 1ll);
    ++ret;
  }
  return ret;
}
map<long long, pair<long long, long long> > ans;
vector<pair<pair<long long, long long>, long long> > v;
int main() {
  int n, m;
  cin >> n >> m;
  long long w, inc;
  for (int i = 0; i < m; i++) {
    cin >> w >> inc;
    v.push_back(make_pair(make_pair(-inc, w), i));
  }
  sort(((v).begin()), ((v).end()));
  int id = 1;
  for (int i = 0; i < m; i++) {
    if (v[i].first.first == -1) {
      int index = v[i].second;
      ans[index] = make_pair(id, id + 1);
      id++;
    }
  }
  id = 1;
  long long nx = id + 2;
  long long mx = max(v[0].first.second, v[1].first.second);
  int j = 2;
  for (int i = n - 1; i < m; i++) {
    long long index = v[i].second;
    long long no = v[i].first.second;
    if (id == nx - 1) {
      nx++;
      mx = max(mx, v[id].first.second);
      id = 1;
    }
    if (no < mx) {
      cout << "-1";
      return 0;
    }
    ans[index] = make_pair(id, nx);
    id++;
  }
  if (v[m - 1].first.second < mx && m != 1) {
    cout << "-1";
    return 0;
  }
  for (int i = 0; i < m; i++)
    cout << ans[i].first << " " << ans[i].second << endl;
}
