#include <bits/stdc++.h>
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int MAXN = 100000 + 10;
const int MOD = 1e9 + 7;
const int dir[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
const int seed = 131;
int cases = 0;
struct Point {
  int w, sign, id;
  bool operator<(const Point &a) const {
    if (w != a.w) return w < a.w;
    return sign > a.sign;
  }
};
std::pair<int, int> ans[MAXN];
std::vector<Point> edges;
std::set<std::pair<int, int> > st;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int w, sign;
    scanf("%d%d", &w, &sign);
    edges.push_back((Point){w, sign, i + 1});
  }
  std::sort(edges.begin(), edges.end());
  int cur = 1, ele = 0;
  for (int i = 0; i < m; i++) {
    if (edges[i].sign) {
      ++cur;
      ans[edges[i].id] = {1, cur};
      for (int j = 2; j < cur && ele < m; j++) {
        st.insert({j, cur});
        ++ele;
      }
    } else {
      if (st.empty()) {
        puts("-1");
        return 0;
      }
      ans[edges[i].id] = *st.begin();
      st.erase(st.begin());
    }
  }
  for (int i = 1; i <= m; i++) printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
