#include <bits/stdc++.h>
using namespace std;
struct data {
  int l, o, id;
  bool operator<(const data &t) const {
    return l < t.l || (l == t.l && o < t.o) ||
           (l == t.l && o == t.o && id < t.id);
  }
};
int n, m;
data a[100005];
pair<int, int> ans[100005];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> a[i].l >> a[i].o;
    a[i].o *= -1;
    a[i].id = i;
  }
  sort(a + 1, a + m + 1);
  int last = 1, f = 2, s = 3;
  for (int i = 1; i <= m; ++i)
    if (a[i].o)
      ans[a[i].id] = pair<int, int>(1, ++last);
    else {
      if (f == s) f = 2, ++s;
      if (s > last) {
        cout << -1;
        return 0;
      }
      ans[a[i].id] = pair<int, int>(f++, s);
    }
  for (int i = 1; i <= m; ++i)
    cout << ans[i].first << " " << ans[i].second << endl;
}
