#include <bits/stdc++.h>
using namespace std;
inline void read(int& buf) {
  buf = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    buf = buf * 10 + c - '0';
    c = getchar();
  }
}
const int maxn = 100000 + 3;
int u[maxn], v[maxn], w[maxn], r[maxn], n, m, pre[maxn], need;
int val[maxn], tof[maxn], shit[maxn];
pair<int, int> ans[maxn];
bool flag[maxn];
bool shit_cmp(const int i, const int j) {
  if (val[i] == val[j])
    return i < j;
  else
    return val[i] < val[j];
}
int find(int x) { return x == pre[x] ? x : pre[x] = find(pre[x]); }
void check(int& from, int& to) {
  ++from;
  if (from < to)
    return;
  else {
    from = 2;
    to++;
  }
}
bool my_cmp(const int i, const int j) { return w[i] < w[j]; }
bool mst() {
  for (int i = 1; i <= n; i++) pre[i] = i;
  int buf = 0;
  for (int i = 1; i <= m; i++) {
    int x = u[i], y = v[i];
    int fx = find(x), fy = find(y);
    if (fx != fy) {
      buf += w[i];
      pre[fy] = fx;
    }
  }
  return buf == need;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    need = 0;
    for (int i = 1; i <= m; i++) {
      read(val[i]);
      read(tof[i]);
      if (tof[i]) need += val[i];
      shit[i] = i;
    }
    sort(shit + 1, shit + 1 + m, shit_cmp);
    int yes = 1, no_from = 1, no_to = 3;
    for (int i = 1; i <= m; i++) {
      int idx = shit[i];
      flag[i] = tof[idx];
      if (tof[idx]) {
        u[i] = 1;
        v[i] = ++yes;
        w[i] = val[idx];
      } else {
        check(no_from, no_to);
        u[i] = no_from;
        v[i] = no_to;
        w[i] = val[idx];
      }
      ans[idx] = make_pair(u[i], v[i]);
    }
    if (mst())
      for (int i = 1; i <= m; i++)
        printf("%d %d\n", ans[i].first, ans[i].second);
    else
      puts("-1");
  }
  return 0;
}
