#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<pair<int, int>, long long> a, pair<pair<int, int>, long long> b) {
  if (a.first.first < b.first.first)
    return true;
  else if (a.first.first > b.first.first)
    return false;
  else {
    if (a.second > b.second)
      return true;
    else
      return false;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  vector<pair<pair<int, int>, long long> > wts;
  long long i;
  for (i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    wts.push_back(make_pair(make_pair(a, i), b));
  }
  sort(wts.begin(), wts.end(), cmp);
  long long j, k;
  i = 1;
  j = i + 2;
  if (wts[0].second == 0 || wts[1].second == 0) {
    cout << "-1\n";
    return 0;
  }
  vector<pair<long long, pair<int, int> > > ans;
  ans.push_back(make_pair(wts[0].first.second, make_pair(1, 2)));
  ans.push_back(make_pair(wts[1].first.second, make_pair(2, 3)));
  long long x;
  k = 3;
  for (x = 2; x < m; x++) {
    if (wts[x].second == 0) {
      if (i > j - 2) {
        j++;
        i = 1;
      }
      if (j > k) {
        cout << "-1\n";
        return 0;
      }
      ans.push_back(make_pair(wts[x].first.second, make_pair(i, j)));
      i++;
    } else {
      ans.push_back(make_pair(wts[x].first.second, make_pair(k, k + 1)));
      k++;
    }
  }
  sort(ans.begin(), ans.end());
  for (i = 0; i < m; i++)
    cout << ans[i].second.first << " " << ans[i].second.second << "\n";
  return 0;
}
