#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
vector<pair<pair<int, int>, int> > tab;
int c[100100] = {0};
int cnt[100100] = {0};
pair<int, int> ans[100100];
int Find(int x) { return (c[x] == x) ? x : Find(c[x]); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    b = 1 - b;
    tab.push_back(make_pair(pair<int, int>(a, b), i));
  }
  sort(tab.begin(), tab.end());
  if (tab[0].first.second) {
    cout << -1 << "\n";
    return 0;
  }
  ans[tab[0].second] = pair<int, int>(1, 2);
  cnt[1] = 3;
  cnt[2] = 3;
  int cur = 3;
  int p = 3;
  for (int i = 1; i < tab.size(); ++i) {
    if (!tab[i].first.second) {
      ans[tab[i].second] = pair<int, int>(1, p);
      cnt[1] = p + 1;
      cnt[p] = p + 1;
      cur = 2;
      p++;
    } else {
      while (cnt[cur] == p) cur++;
      if (cur == p) {
        cout << -1 << "\n";
        return 0;
      } else {
        ans[tab[i].second] = pair<int, int>(cur, cnt[cur]);
        cnt[cur]++;
      }
    }
  }
  for (int i = 0; i < tab.size(); ++i)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
