#include <bits/stdc++.h>
using namespace std;
inline void err(istringstream *iss) {}
template <typename T, typename... Args>
void err(istringstream *iss, const T &$val, const Args &...args) {
  string $name;
  *iss >> $name;
  if ($name.back() == ',') $name.pop_back();
  cout << $name << " = " << $val << "; ", err(iss, args...);
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
int n, m, K, T, Q, cn;
struct Edge {
  int w, taken, idx;
} e[100005];
int qh, qt, ec = 1;
pair<int, int> q[100005], ans[100005];
struct cmp {
  bool operator()(const Edge &ls, const Edge &rs) const {
    return tie(ls.w, rs.taken) < tie(rs.w, ls.taken);
  }
};
int main() {
  cin.tie(NULL);
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &e[i].w, &e[i].taken), e[i].idx = i;
  }
  sort(e, e + m, cmp());
  for (int i = 0; i < m; i++) {
    if (e[i].taken) {
      ans[e[i].idx] = {ec, ec + 1}, ec++;
      for (int j = 1; j <= ec - 2; j++) {
        if (qt == 100005) break;
        q[qt++] = {j, ec};
      }
    } else {
      if (qh >= qt) return printf("-1\n"), 0;
      ans[e[i].idx] = q[qh++];
    }
  }
  for (int i = 0; i < m; i++) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}
