#include <bits/stdc++.h>
using namespace std;
const int INF = (unsigned)-1 >> 1;
const long long inf = (unsigned long long)-1 >> 1;
template <class T>
void rd(T &a) {
  a = 0;
  char c;
  while (c = getchar(), !isdigit(c))
    ;
  do a = a * 10 + (c ^ 48);
  while (c = getchar(), isdigit(c));
}
template <class T>
void nt(T x) {
  if (!x) return;
  nt(x / 10);
  putchar(48 + x % 10);
}
template <class T>
void pt(T x) {
  if (!x)
    putchar('0');
  else
    nt(x);
}
template <class T>
void Max(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
void Min(T &a, T b) {
  if (a == -1 || a > b) a = b;
}
const int M = 1e5 + 5;
int A[M], B[M];
struct E {
  int val, psb, id;
  inline bool operator<(const E &tmp) const {
    return val < tmp.val || val == tmp.val && psb > tmp.psb;
  }
} Edge[M];
int a[M], b[M];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    rd(a[i]), rd(b[i]);
    Edge[i] = (E){a[i], b[i], i};
  }
  sort(Edge + 1, Edge + m + 1);
  for (int i = 1, l = 1, w = 1, r = 2; i <= m; ++i) {
    if (Edge[i].psb) {
      ++w;
      A[Edge[i].id] = w - 1, B[Edge[i].id] = w;
      if (w > n) return puts("-1");
    } else {
      if (l + 1 == r) l = 1, r++;
      if (r > w) return puts("-1");
      A[Edge[i].id] = l, B[Edge[i].id] = r;
      ++l;
    }
  }
  for (int i = 1; i <= m; ++i) pt(A[i]), putchar(' '), pt(B[i]), putchar('\n');
  return 0;
}
