#include <bits/stdc++.h>
using namespace std;
int n, m;
int W[100005], B[100005];
vector<int> id, mst, ot;
pair<int, int> A[100005];
set<int> S[100005];
int cnt[100005];
bool cmp(int a, int b) {
  if (W[a] == W[b]) return B[a] > B[b];
  return W[a] < W[b];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &W[i], &B[i]);
    id.push_back(i);
  }
  sort(id.begin(), id.end(), cmp);
  int cur = n - 1;
  for (int i = 0; i < m; i++) {
    int idx = id[i];
    if (B[idx] == 1 && mst.size() < n - 1) {
      A[idx] = make_pair(n, n - mst.size() - 1);
      cnt[n - mst.size() - 1]++;
      S[n].insert(n - mst.size() - 1);
      mst.push_back(idx);
    } else {
      while (true) {
        if (cur == 0 || cnt[cur] == 0) {
          printf("-1\n");
          return 0;
        }
        if (cur + cnt[cur] > n) {
          cur--;
        } else {
          if (S[cnt[cur] + cur].find(cur) != S[cur + cnt[cur]].end())
            cnt[cur]++;
          else {
            S[cur + cnt[cur]].insert(cur);
            A[idx] = make_pair(cur, cnt[cur] + cur);
            break;
          }
        }
      }
      ot.push_back(idx);
    }
  }
  for (int i = 0; i < m; i++) {
    printf("%d %d\n", A[i].first, A[i].second);
  }
  return 0;
}
