#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
struct Node {
  int w, flag, id;
  bool operator<(const Node& e) const {
    if (w == e.w) return flag > e.flag;
    return w < e.w;
  }
} data[MAXN];
int n, m, u = 1, x = 1, y = 3, edge[MAXN][2];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++)
    scanf("%d %d", &data[i].w, &data[i].flag), data[i].id = i;
  sort(data + 1, data + 1 + m);
  for (int i = 1; i <= m; i++) {
    if (data[i].flag) {
      edge[data[i].id][0] = u;
      edge[data[i].id][1] = u + 1;
      ++u;
    } else {
      if (y > u) {
        puts("-1");
        return 0;
      } else {
        edge[data[i].id][0] = x;
        edge[data[i].id][1] = y;
        ++x;
        if (y - x <= 1) ++y, x = 1;
      }
    }
  }
  for (int i = 1; i <= m; i++) printf("%d %d\n", edge[i][0], edge[i][1]);
}
