#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long int value[100010];
long long int solve() {
  long long int n, m;
  cin >> n >> m;
  std::vector<pair<long long int, long long int>> ans(m);
  std::vector<pair<long long int, long long int>> one;
  std::vector<pair<long long int, long long int>> zero;
  for (long long int i = 0; i < m; i++) {
    long long int a, b;
    cin >> a >> b;
    if (b == 0) {
      zero.push_back(make_pair(a, i));
    } else {
      one.push_back(make_pair(a, i));
    }
  }
  sort(one.begin(), one.end());
  for (long long int i = 0; i < n - 1; i++) {
    long long int x, y;
    x = one[i].first;
    y = one[i].second;
    value[i + 1] = x;
    ans[y] = make_pair(i + 1, n);
  }
  sort(zero.begin(), zero.end());
  long long int ind = 0;
  long long int x, y;
  y = 2;
  x = 1;
  while (ind < (long long int)zero.size()) {
    long long int a, b;
    a = value[x];
    b = value[y];
    long long int tmp_ind = zero[ind].second;
    long long int element = zero[ind].first;
    if ((element < a) || (element < b)) {
      y++;
      x = y - 1;
    } else {
      ans[tmp_ind] = make_pair(x, y);
      x--;
      ind++;
      if (x == 0) {
        y++;
        x = y - 1;
      }
    }
    if (ind == (long long int)zero.size()) {
      break;
    }
    if (y == n) {
      cout << "-1\n";
      return 0;
    }
  }
  for (long long int i = 0; i < m; i++) {
    cout << ans[i].first << " " << ans[i].second << "\n";
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
