#include <bits/stdc++.h>
using namespace std;
const int maxx = 200010;
vector<int> g[maxx];
int t, n, m, a, b;
int ans = 0, total = 0, cnt = 0, l = 1, r = 2, l1 = 1, r1 = 3;
struct no {
  int x;
  int y;
} e[maxx];
struct node {
  long long val;
  int mark;
  int num;
} s[maxx];
bool cmp(node a, node b) {
  if (a.val == b.val) return a.mark > b.mark;
  return a.val < b.val;
}
int main() {
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= m; i++) {
    scanf("%lld%d", &s[i].val, &s[i].mark);
    s[i].num = i;
  }
  sort(s + 1, s + m + 1, cmp);
  for (register int i = 1; i <= m; i++) {
    if (s[i].mark) {
      if (r == n + 1) {
        e[s[i].num].x = l1;
        e[s[i].num].y = r1;
        l1++;
        if (r1 - l1 == 1) {
          l1 = 1;
          r1++;
        }
      } else {
        e[s[i].num].x = l;
        e[s[i].num].y = r;
        l++;
        r++;
      }
    } else {
      if (r1 >= r) {
        ans = -1;
        break;
      } else {
        e[s[i].num].x = l1;
        e[s[i].num].y = r1;
        l1++;
        if (r1 - l1 == 1) {
          l1 = 1;
          r1++;
        }
      }
    }
  }
  if (ans == -1)
    printf("-1");
  else {
    for (register int i = 1; i <= m; i++) printf("%d %d\n", e[i].x, e[i].y);
  }
  return 0;
}
