#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 100000 + 7;
const long long MOD = 1e9 + 7;
struct pop {
  int v, p, i;
} pos[MAXN];
bool cmp1(pop x, pop y) {
  if (x.v == y.v) return x.p > y.p;
  return x.v < y.v;
}
queue<pop> s;
map<int, pop> mp;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int cnt = 0;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &pos[i].v, &pos[i].p);
    pos[i].i = i;
    if (pos[i].p == 0) cnt++;
  }
  sort(pos + 1, pos + 1 + m, cmp1);
  int now = 1, flag = 0;
  for (int i = 1; i <= m; i++) {
    if (pos[i].p == 0) {
      if (s.empty()) {
        flag = 1;
        break;
      } else {
        pop x = s.front();
        mp[pos[i].i].p = x.p;
        mp[pos[i].i].v = x.v;
        s.pop();
        cnt--;
      }
    } else {
      now++;
      if (now > n) {
        flag = 1;
        break;
      }
      mp[pos[i].i].p = 1;
      mp[pos[i].i].v = now;
      for (int j = 2; j < now; j++) {
        if (s.size() > cnt) {
          break;
        }
        pop x;
        x.p = j;
        x.v = now;
        s.push(x);
      }
    }
  }
  if (flag == 1)
    printf("-1\n");
  else {
    for (int i = 1; i <= m; i++) {
      printf("%d %d\n", mp[i].p, mp[i].v);
    }
  }
}
