#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<long long int, pair<long long int, long long int> > a,
         pair<long long int, pair<long long int, long long int> > b) {
  pair<long long int, long long int> aa = a.second;
  pair<long long int, long long int> bb = b.second;
  return (aa.first == bb.first) ? (aa.second > bb.second)
                                : (aa.first < bb.first);
}
vector<long long int> kp;
vector<long long int> lis[100009];
vector<pair<long long int, long long int> > ans;
vector<pair<long long int, pair<long long int, long long int> > > adj;
long long int ind[100009], mrk[100009];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, m, i, j, f = 0, w, c, toc[100009], u, v;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> w >> c;
    adj.push_back(pair<long long int, pair<long long int, long long int> >(
        i, pair<long long int, long long int>(w, c)));
    ans.push_back(pair<long long int, long long int>(0, 0));
  }
  ans.push_back(pair<long long int, long long int>(0, 0));
  sort(adj.begin(), adj.end(), cmp);
  for (i = 2; i <= n; i++) {
    toc[i - 2] = i;
    kp.push_back(n - i + 2);
    lis[i].push_back(i);
  }
  f = 0;
  long long int k = 0, l, mi, r;
  for (i = 0; i < m; i++) {
    j = adj[i].first;
    w = (adj[i].second).first;
    c = (adj[i].second).second;
    if (c == 1) {
      u = toc[f++];
      ans[j] = pair<long long int, long long int>(1, u);
      ind[1]++;
      mrk[u] = 1;
      k++;
    }
    if (c == 0) {
      l = 2;
      r = k + 1;
      u = n;
      while (l <= r) {
        mi = (l + r) / 2;
        if (ind[mi] < k - mi + 1 && ind[mi - 1] >= k - mi + 2) {
          u = mi;
          break;
        } else if (ind[mi] < k - mi + 1 && ind[mi - 1] < k - mi + 2)
          r = mi - 1;
        else if (ind[mi] >= k - mi + 1)
          l = mi + 1;
      }
      v = lis[u][(long long int)(lis[u].size() - 1)] + 1;
      ind[u]++;
      lis[u].push_back(v);
      if (mrk[u] == 1 && mrk[v] == 1)
        ans[j] = pair<long long int, long long int>(u, v);
      else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (i = 1; i <= m; i++) cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
