#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const long double pi = acos(-1.0);
const int inf = 1e+9;
#pragma comment(linker, "/STACK:99999999999")
template <typename T>
istream &operator>>(istream &, vector<T> &);
template <typename T>
ostream &operator<<(ostream &, const vector<T> &);
struct Edge {
  int cost, type, id;
  bool operator<(const Edge &other) const {
    return make_pair(cost, 1 - type) < make_pair(other.cost, 1 - other.type);
  }
};
const int M = 1e5 + 100;
Edge edges[M];
pair<int, int> ans[M];
int cnt[M];
bool solve() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d", &edges[i].cost, &edges[i].type);
    edges[i].id = i;
  }
  sort(edges, edges + m);
  int size = 0;
  int idx = 0;
  for (int e = 0; e < m; ++e) {
    auto edge = edges[e];
    if (edge.type == 1) {
      ++size;
      ans[edge.id].first = cnt[size]++;
      ans[edge.id].second = size;
    } else {
      while (idx < size && cnt[idx] == idx) ++idx;
      if (cnt[idx] == idx) return false;
      int u = cnt[idx];
      int v = idx;
      ++cnt[idx];
      ans[edge.id].first = u;
      ans[edge.id].second = v;
    }
  }
  assert(size + 1 == n);
  for (int i = 0; i < m; ++i) {
    printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
  }
  return true;
}
int main() {
  clock_t _clock = clock();
  ;
  if (!solve()) {
    puts("-1");
  }
  return 0;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (int i = 0; i < v.size(); ++i) {
    is >> v[i];
  }
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < v.size(); ++i) {
    if (i) os << " ";
    os << v[i];
  }
  return os;
}
