#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1.0);
const long double eps = 1e-8;
const int maxn = 1e5 + 5;
const int maxm = 3e4 + 5;
const long long mod = 1e9 + 7;
const long long inf = 2e18 + 5;
const int _inf = -1e9 + 7;
inline int scan() {
  int m = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') m = m * 10 + c - '0', c = getchar();
  return m;
}
int N, Q, H, M, L, K, P;
int xx[] = {0, 0, 1, -1};
int yy[] = {1, -1, 0, 0};
int f[maxn];
struct node {
  int a, b, id;
  node() {}
  node(int a, int b, int id) : a(a), b(b), id(id) {}
  bool operator<(const node& t) const { return a < t.a || a == t.a && b > t.b; }
} lk[maxn];
pair<int, int> ans[maxn];
int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    f[i] = i;
  }
  for (int i = 0; i < M; i++) {
    scanf("%d%d", &lk[i].a, &lk[i].b);
    lk[i].id = i;
  }
  sort(lk, lk + M);
  bool wa = 0;
  P = 2;
  K = 1;
  for (int i = 0; i < M && !wa; i++) {
    if (lk[i].b) {
      ans[lk[i].id] = make_pair(1, ++K);
      P = 2;
    } else {
      bool ff = 0;
      for (int j = P; j <= K; j++) {
        if (f[j] < K) {
          ans[lk[i].id] = make_pair(j, f[j] + 1);
          f[j]++;
          ff = 1;
          break;
        } else
          P++;
      }
      if (!ff) {
        puts("-1");
        exit(0);
      }
    }
  }
  for (int i = 0; i < M; i++) printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
