#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
inline void smax(T1 &a, T2 b) {
  if (a < b) a = b;
}
vector<pair<pair<int, int>, int> > edges;
int n, m;
pair<int, int> edge[100100];
int weight[100100];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int w, b;
    cin >> w >> b;
    edges.push_back({{w, 1 - b}, i});
  }
  sort((edges).begin(), (edges).end());
  deque<pair<int, int> > st;
  char impossible = 0;
  int N = 1;
  for (int i = 0; i < m; ++i) {
    int w = edges[i].first.first;
    int type = edges[i].first.second;
    int idx = edges[i].second;
    if (type == 0) {
      N++;
      edge[idx] = {1, N};
      int j = 2;
      while (j < N) {
        st.push_back({j, N});
        if (((int)(st).size()) == m + 1) {
          st.pop_back();
          break;
        }
        ++j;
      }
    } else {
      if (((int)(st).size()) == 0) {
        impossible = 1;
        break;
      }
      auto t = st.front();
      st.pop_front();
      edge[idx] = t;
    }
  }
  if (impossible)
    cout << -1 << endl;
  else {
    for (int i = 0; i < m; ++i) {
      cout << edge[i].first << ' ' << edge[i].second << endl;
    }
  }
  return 0;
}
