#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
int n, m;
struct node {
  int w, id, flag;
  inline void Read() {
    w = read();
    flag = read();
  }
} g[100010];
inline int cmp(const node &a, const node &b) {
  return (a.w != b.w) ? a.w < b.w : a.flag > b.flag;
}
struct Point {
  int x, y;
  inline Point(int x_ = 0, int y_ = 0) {
    x = x_;
    y = y_;
  }
} Ans[100010];
int main() {
  n = read();
  m = read();
  for (int i = (1); i <= (m); i++) g[i].Read(), g[i].id = i;
  sort(g + 1, g + m + 1, cmp);
  int TT = 1;
  int Now = 3, ST = 1;
  for (int i = (1); i <= (m); i++)
    if (g[i].flag) {
      Ans[g[i].id] = Point(TT, TT + 1);
      TT++;
    } else {
      if (Now > TT) {
        printf("-1\n");
        return 0;
      }
      Ans[g[i].id] = Point(ST, Now);
      ST++;
      if (ST + 1 == Now) {
        Now++;
        ST = 1;
      }
    }
  for (int i = (1); i <= (m); i++) {
    printf("%d %d\n", Ans[i].x, Ans[i].y);
  }
}
