#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n, m;
  scanf("%d%d", &n, &m);
  pair<pair<int, int>, int> a[m];
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    a[i] = make_pair(pair<int, int>(x, -1 * y), i);
  }
  sort(a, a + m);
  pair<int, int> ans[m];
  int cur = 1, nxt = 1;
  int cnt = 1;
  for (int i = 0; i < m; i++) {
    if (a[i].first.second == -1) {
      cnt++;
      ans[a[i].second] = make_pair(1, cnt);
    } else {
      if (cur < nxt) {
        ans[a[i].second] = make_pair(cur, nxt);
        cur++;
      } else if (cur == nxt) {
        if (nxt < cnt) {
          nxt++;
          cur = 2;
          i--;
          continue;
        } else {
          printf("-1\n");
          return 0;
        }
      } else {
        assert(1 < 0);
      }
    }
  }
  for (int i = 0; i < m; i++) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}
