#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p) {
  return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc) {
  o << "{";
  for (const T& v : vc) o << v << ",";
  o << "}";
  return o;
}
struct timer {
  double t;
  timer() { t = clock(); }
  ~timer() { printf("\nruntime %.3f s\n", get_time()); }
  double get_time() { return (clock() - t) / CLOCKS_PER_SEC; }
};
long long n, m, x[100065], y[100065];
vector<pair<pair<long long, long long>, long long>> v;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    long long x, y;
    cin >> x >> y;
    v.push_back({{x, y}, i});
  }
  for (long long i = 0; i < m; i++) {
    v[i].first.second ^= 1;
  }
  sort(v.begin(), v.end());
  long long cur = 2, sum = 0, cnt = 0, idx = 0, s = 0;
  for (auto t : v) {
    long long f = t.first.second;
    long long id = t.second;
    if (f == 0) {
      x[id] = 0;
      sum += cnt;
      y[id] = cnt + 1;
      cnt++;
      continue;
    }
    if (sum == s) {
      cout << -1 << endl;
      return 0;
    }
    s++;
    idx++;
    if (cur == idx) {
      idx = 1;
      cur++;
    }
    x[id] = cur;
    y[id] = idx;
  }
  for (long long i = 1; i <= m; i++)
    cout << x[i] + 1 << " " << y[i] + 1 << endl;
  return 0;
}
