#include <bits/stdc++.h>
using namespace std;
int n, m;
pair<int, int> p[100005], ans[100005];
int tot, start[100005], remain, now;
int f[100005];
priority_queue<pair<int, int> > Q;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &p[i].first, &p[i].second);
    if (p[i].second == 0) p[i].second = -1;
    p[i].second = -p[i].second;
    p[i].second *= i;
  }
  sort(p + 1, p + m + 1);
  for (int i = 1; i <= n; i++) f[i] = i, start[i] = i + 1;
  remain = 1;
  now = 1;
  for (int i = 1; i <= m; i++) {
    if (p[i].second > 0) {
      if (Q.empty()) {
        return puts("-1"), 0;
      } else {
        int x = Q.top().first, y = Q.top().second;
        Q.pop();
        if (-x <= remain) {
          ans[p[i].second] = make_pair(-x, y);
          if (-x != n) Q.push(make_pair(x - 1, y));
        } else {
          return puts("-1");
        }
      }
    } else {
      remain++;
      if (remain <= n) {
        Q.push(make_pair(-remain - 1, remain));
        ans[-p[i].second] = make_pair(1, remain);
      } else {
        return puts("-1"), 0;
      }
    }
  }
  for (int i = 1; i <= m; i++) printf("%d %d\n", ans[i].first, ans[i].second);
}
