#include <bits/stdc++.h>
using namespace std;
struct edge {
  int wei, idx;
};
pair<int, int> ans[100009];
vector<edge> tree, nontree;
int cnt[100009];
bool cmp(struct edge lhs, struct edge rhs) { return lhs.wei < rhs.wei; }
int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = int(0); i <= int(m - 1); i++) {
    int we, id;
    scanf("%d", &we);
    scanf("%d", &id);
    struct edge k;
    k.wei = we;
    k.idx = i;
    if (id == 1)
      tree.push_back(k);
    else
      nontree.push_back(k);
  }
  sort(tree.begin(), tree.end(), cmp);
  sort(nontree.begin(), nontree.end(), cmp);
  for (int i = int(0); i <= int(tree.size() - 1); i++)
    ans[tree[i].idx] = pair<int, int>(i + 1, i + 2);
  bool ch = true;
  int low = 1, maxi = tree[low].wei, i = 0;
  while (i < nontree.size() && low < tree.size()) {
    if (nontree[i].wei >= maxi) {
      ans[nontree[i].idx] = pair<int, int>(cnt[low] + 1, low + 2);
      cnt[low]++;
      if (cnt[low] == low) {
        low++;
        if (low < tree.size()) maxi = tree[low].wei;
      }
    } else
      break;
    i++;
  }
  if (i == nontree.size()) {
    for (int i = int(0); i <= int(m - 1); i++) {
      printf("%d %d\n", ans[i].first, ans[i].second);
    }
  } else {
    printf("-1\n");
  }
  return 0;
}
