#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
using pii = pair<int, int>;
const double PI = 2 * asin(1);
struct Edge {
  int w, id, flag;
  Edge(int w = 0, int id = 0, int flag = 0) : w(w), id(id), flag(flag) {}
  bool operator<(const Edge &e) const {
    if (w == e.w) return flag > e.flag;
    return w < e.w;
  }
};
int g_n, g_m;
vector<bool> vb;
vector<Edge> ve;
vector<pii> vpii_ans;
void pretreat() {}
bool input() {
  cin >> g_n >> g_m;
  if (cin.eof()) return false;
  vb.clear(), vb.resize(g_n + 1);
  ve.clear(), ve.emplace_back();
  vpii_ans.clear(), vpii_ans.resize(g_m + 1);
  for (int i = 1, w, flag; i <= g_m; ++i) {
    scanf(" %d %d", &w, &flag);
    ve.emplace_back(w, i, flag);
  }
  return true;
}
void solve() {
  sort(ve.begin() + 1, ve.end());
  int u = 1, v = 3, cnt = 1;
  for (int i = 1; i <= g_m; ++i) {
    Edge &e = ve[i];
    if (e.flag == 1) {
      vpii_ans[e.id].first = cnt;
      vb[cnt] = true;
      vpii_ans[e.id].second = ++cnt;
      vb[cnt] = true;
    } else {
      if (vb[v] != true) {
        puts("-1");
        return;
      }
      vpii_ans[e.id].first = u, vpii_ans[e.id].second = v;
      ++u;
      if (u == v - 1) {
        u = 1;
        ++v;
      }
    }
  }
  for (int i = 1; i <= g_m; ++i) {
    printf("%d %d\n", vpii_ans[i].first, vpii_ans[i].second);
  }
}
int main() {
  pretreat();
  while (input()) {
    solve();
  }
  return 0;
}
