#include <bits/stdc++.h>
using namespace std;
long long int vis[1000001];
long long int cap[1000002];
vector<long long int> v;
vector<pair<pair<long long int, long long int>, long long int> > t;
vector<pair<long long int, pair<long long int, long long int> > > ans;
pair<long long int, long long int> p;
long long int z;
void fail() {
  cout << "-1";
  exit(0);
}
int main() {
  long long int i, j, k, l, sum, r, n, m, x, y, q;
  cin >> n >> m;
  for (i = 1; i <= n; i++) cap[i] = i + 2;
  for (i = 1; i <= m; i++) {
    cin >> x >> y;
    if (y == 0)
      y = 1;
    else
      y = 0;
    p = make_pair(x, y);
    t.push_back(make_pair(p, i));
  }
  sort(t.begin(), t.end());
  vis[1] = 1;
  v.push_back(1);
  q = 2;
  l = 1;
  for (i = 0; i < m; i++) {
    p = t[i].first;
    z = t[i].second;
    x = p.first;
    y = p.second;
    if (y == 0) {
      vis[q] = 1;
      p = make_pair(q - 1, q);
      ans.push_back(make_pair(z, p));
      v.push_back(q);
      q++;
      l = 1;
    } else {
      while (1) {
        if (l >= q - 1) {
          fail();
        }
        if (cap[l] > q - 1) {
          l++;
          continue;
        }
        p = make_pair(l, cap[l]);
        ans.push_back(make_pair(z, p));
        cap[l]++;
        break;
      }
    }
  }
  sort(ans.begin(), ans.end());
  for (i = 0; i < ans.size(); i++)
    cout << ans[i].second.first << " " << ans[i].second.second << endl;
}
