#include <bits/stdc++.h>
using namespace std;
class node {
 public:
  long long int second;
  long long int length;
};
void FastIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  long long int n, m, i;
  cin >> n >> m;
  pair<pair<long long int, long long int>, long long int> p[m];
  for (i = 0; i < m; i++)
    cin >> p[i].first.first >> p[i].first.second, p[i].first.second ^= 1,
        p[i].second = i;
  sort(p, p + m);
  long long int j = 1, k = 1, r = 3;
  vector<pair<long long int, long long int> > a;
  for (i = 0; i < m; i++) {
    if (p[i].first.second == 0) {
      a.push_back(make_pair(j, j + 1));
      j++;
    } else {
      if (r > j && k > j) break;
      if (k > r - 2) k = 1, r++;
      if (r <= j && k <= j) a.push_back(make_pair(r, k)), k += 1;
    }
  }
  if (i != m || a.size() != m) {
    cout << "-1\n";
    return 0;
  }
  pair<long long int, long long int> ans[m];
  for (i = 0; i < a.size(); i++) ans[p[i].second] = a[i];
  for (i = 0; i < a.size(); i++)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
