#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e6 + 5;
struct comp {
  bool operator()(pair<int, int> &a, pair<int, int> &b) {
    if (a.first == b.first) return (a.second < b.second);
    return (a.first > b.first);
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> ed(m);
  map<pair<int, int>, queue<int>> pos;
  priority_queue<pair<int, int>, vector<pair<int, int>>, comp> p;
  for (int i = 0; i < m; i++) {
    cin >> ed[i].first >> ed[i].second;
    p.push(ed[i]);
    pos[ed[i]].push(i);
  }
  vector<int> q;
  int i = 1, x = 2;
  queue<int> avl;
  q.push_back(i++);
  int s = q.size();
  vector<pair<int, int>> res(m);
  bool check = true;
  while (!p.empty()) {
    pair<int, int> v = p.top();
    p.pop();
    int j = pos[v].front();
    pos[v].pop();
    if (v.second) {
      res[j] = {q.back(), i};
      q.push_back(i++);
      if (q.size() > 2) avl.push(q.size() - 1);
    } else if (!avl.empty()) {
      int t = avl.front();
      if (t - x >= 0) {
        res[j] = {q[t], q[t - x]};
        x++;
      } else if (avl.size() == 1) {
        check = false;
        break;
      } else {
        avl.pop();
        t = avl.front();
        x = 2;
        res[j] = {q[t], q[t - x]};
        x++;
      }
    } else {
      check = false;
      break;
    }
  }
  if (check) {
    for (pair<int, int> t : res) cout << t.first << " " << t.second << '\n';
  } else
    cout << -1;
}
