#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1280000000")
using namespace std;
void solve();
void precalc();
clock_t start;
int testNumber = 1;
bool todo = true;
int main() {
  start = clock();
  int t = 1;
  cout.sync_with_stdio(0);
  cin.tie(0);
  precalc();
  cout.precision(10);
  cout << fixed;
  int testNum = 1;
  while (t--) {
    solve();
    ++testNumber;
  }
  return 0;
}
template <typename T>
T binpow(T q, T w, T mod) {
  if (!w) return 1 % mod;
  if (w & 1) return q * 1LL * binpow(q, w - 1, mod) % mod;
  return binpow(q * 1LL * q % mod, w / 2, mod);
}
void precalc() {}
template <typename T>
T gcd(T q, T w) {
  while (w) {
    q %= w;
    swap(q, w);
  }
  return q;
}
template <typename T>
T lcm(T q, T w) {
  return q / gcd(q, w) * w;
}
struct Edge {
  int w;
  int into;
  int id;
  void scan() { cin >> w >> into; }
  bool operator<(const Edge& ot) const {
    return make_pair(into ^ 1, w) < make_pair(ot.into ^ 1, ot.w);
  }
};
void solve() {
  int n, m;
  cin >> n >> m;
  vector<Edge> edges(m);
  for (int i = 0; i < m; ++i) {
    edges[i].scan();
    edges[i].id = i;
  }
  sort(edges.begin(), edges.end());
  vector<pair<int, int>> res(m);
  for (int i = 0; i < n - 1; ++i) {
    res[edges[i].id] = make_pair(i, i + 1);
  }
  int last = 2;
  int prev = 0;
  for (int i = n - 1; i < m; ++i) {
    res[edges[i].id] = make_pair(prev, last);
    if (edges[last - 1].w > edges[i].w) {
      cout << "-1\n";
      return;
    }
    ++prev;
    if (prev + 1 == last) {
      ++last;
      prev = 0;
    }
  }
  for (int i = 0; i < m; ++i) {
    cout << res[i].first + 1 << ' ' << res[i].second + 1 << "\n";
  }
}
