#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, maxn = 200005, ln = 17;
const int shift = 30, etf = mod - 1;
const int inf = (int)1e9;
pair<pair<int, int>, int> in[maxn];
pair<int, int> ans[maxn];
pair<int, int> cal[maxn];
void pre() {
  int p = 1, q = 3;
  for (int i = 0; i < maxn; i++) {
    if (q - p == 1) {
      p = 1;
      q++;
    }
    cal[i].first = p;
    cal[i].second = q;
    p++;
  }
}
void _debug(int n, int m) {
  for (int i = 0; i < m; i++) {
    cout << in[i].first.first << " " << in[i].first.second << " "
         << in[i].second << endl;
  }
  for (int i = 0; i < 10; i++) {
    cout << cal[i].first << " " << cal[i].second << endl;
  }
}
int main() {
  pre();
  int m, n;
  cin >> n >> m;
  int flag = 0;
  for (int i = 0; i < m; i++) {
    int p, q;
    scanf("%d", &p);
    scanf("%d", &q);
    in[i].first.first = p;
    in[i].first.second = -q;
    in[i].second = i;
  }
  sort(in, in + m);
  int cnt = 1;
  int ptr = 0;
  for (int i = 0; i < m; i++) {
    if (in[i].first.second == 0) {
      if (cnt < cal[ptr].second) {
        flag++;
        break;
      }
      ans[in[i].second].first = cal[ptr].first;
      ans[in[i].second].second = cal[ptr].second;
      ptr++;
    } else {
      ans[in[i].second].first = cnt;
      cnt++;
      ans[in[i].second].second = cnt;
    }
  }
  if (flag)
    cout << "-1" << endl;
  else {
    for (int i = 0; i < m; i++)
      cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}
