#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int, int>>;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<tuple<int, int, int>> ve;
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    ve.emplace_back(x, -y, i);
  }
  sort((ve).begin(), (ve).end());
  vii edge(m);
  int last = 1;
  set<pair<int, int>> cur;
  cur.insert({last, last});
  for (auto t : ve) {
    int a, b, c;
    tie(a, b, c) = t;
    if (b) {
      assert(cur.rbegin()->first == last && cur.rbegin()->second == last);
      ++last;
      edge[c] = {last - 1, last};
      auto it = cur.end();
      cur.erase(prev(it));
      cur.insert({last, last - 1});
      cur.insert({last, last});
    } else {
      int u = cur.begin()->first, v = cur.begin()->second;
      if (u == last) {
        puts("-1");
        return 0;
      } else {
        cur.erase(cur.begin());
        ++u;
        edge[c] = {v, u};
        cur.insert({u, v});
      }
    }
  }
  for (auto e : edge) printf("%d %d\n", e.first, e.second);
}
