#include <bits/stdc++.h>
using namespace std;
int deg[100005], arr[100005];
pair<int, int> ans[100005];
set<pair<int, int> > Set;
vector<pair<pair<int, int>, int> > edge;
int main() {
  int n, m, first = 2, second = 2, num = 2;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    edge.push_back(make_pair(make_pair(a, 1 - b), i));
  }
  sort(edge.begin(), edge.end());
  for (int i = 0; i < m; i++) {
    if (edge[i].first.second == 1) {
      if (first >= second) {
        first = 2, second++;
      }
      if (second >= num) {
        printf("-1\n");
        return 0;
      }
      ans[edge[i].second] = make_pair(first++, second);
    } else {
      ans[edge[i].second] = make_pair(1, num++);
    }
  }
  int a, b;
  a = b = 0;
  for (int i = 0; i < edge.size(); i++) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}
