#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print(vector<T> vec, bool next_line = true) {
  for (T element : vec) {
    cout << element << " ";
  }
  if (next_line) {
    cout << endl;
  }
}
class Graph {
 public:
  int next_ver = 2;
  vector<pair<int, int> > edges, free_edges;
  bool add_edge(int mst_ver = -1) {
    if (mst_ver != -1) {
      edges.emplace_back(1, mst_ver);
      return true;
    }
    if (free_edges.size() == 0) {
      return false;
    }
    edges.push_back(free_edges.back());
    free_edges.pop_back();
    return true;
  }
  void add_free_edge(int from, int to) { free_edges.emplace_back(from, to); }
  bool build(vector<pair<long long, long long> > &weights, int n) {
    for (int i = 0; i < weights.size(); ++i) {
      int all = 1, belong = weights[i].second;
      while (i + 1 < weights.size() &&
             weights[i + 1].first == weights[i].first) {
        all += 1;
        belong += weights[i + 1].second;
        i += 1;
      }
      if (free_edges.size() < 100000) {
        for (int j = 0; j < belong && free_edges.size() < 100000; ++j) {
          for (int k = 2; k < next_ver && free_edges.size() < 100000; ++k) {
            if (k == next_ver + j) {
              continue;
            }
            add_free_edge(next_ver + j, k);
          }
        }
        for (int j = 0; j < belong && free_edges.size() < 100000; ++j) {
          for (int k = j + 1; k < belong && free_edges.size() < 100000; ++k) {
            add_free_edge(next_ver + j, next_ver + k);
          }
        }
      }
      for (int j = 0; j < all - belong; ++j) {
        if (!add_edge()) {
          return false;
        }
      }
      for (int j = 0; j < belong; ++j) {
        add_edge(next_ver + j);
      }
      next_ver += belong;
    }
    return next_ver == n + 1;
  }
} graph;
class Edge {
 public:
  long long weight, belong, number;
  Edge() {}
  Edge(long long weight, long long belong, long long number)
      : weight(weight), belong(belong), number(number) {}
  bool operator<(const Edge &edge) const {
    return make_pair(weight, belong) < make_pair(edge.weight, edge.belong);
  }
};
void solve() {
  int n, m;
  cin >> n >> m;
  vector<pair<long long, long long> > weights;
  vector<Edge> edges;
  weights.resize(m);
  for (int i = 0; i < m; ++i) {
    cin >> weights[i].first >> weights[i].second;
    edges.emplace_back(Edge(weights[i].first, weights[i].second, i));
  }
  sort(weights.begin(), weights.end());
  sort(edges.begin(), edges.end());
  if (!graph.build(weights, n)) {
    cout << -1;
    return;
  }
  vector<long long> per(m);
  for (int i = 0; i < m; ++i) {
    per[edges[i].number] = i;
  }
  for (int i = 0; i < m; ++i) {
    cout << graph.edges[per[i]].first << " " << graph.edges[per[i]].second
         << endl;
  }
}
int main() {
  solve();
  return 0;
}
