#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
pair<int, int> p[N];
pair<int, int> ans[N];
int parent[N], height[N];
vector<int> v;
struct DSU {
  int parent[N];
  int sz[N];
  DSU() {
    for (int i = 0; i < N; ++i) parent[i] = i;
    fill(sz, sz + N, 1);
  }
  int findParent(int i) {
    if (parent[i] == i) return i;
    return parent[i] = findParent(parent[i]);
  }
  bool areTeam(int x, int y) {
    int leader1 = findParent(x);
    int leader2 = findParent(y);
    return leader1 == leader2;
  }
  void mergeTeams(int x, int y) {
    int leader1 = findParent(x);
    int leader2 = findParent(y);
    if (leader1 == leader2) return;
    if (sz[leader1] > sz[leader2]) {
      parent[leader2] = leader1;
      sz[leader1] += sz[leader2];
      sz[leader2] = 0;
    } else {
      parent[leader1] = leader2;
      sz[leader2] += sz[leader1];
      sz[leader1] = 0;
    }
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, w, o;
  cin >> n >> m;
  long long sum1 = 0, sum2 = 0;
  for (int i = 0; i < m; ++i) {
    cin >> p[i].first >> p[i].second;
    if (p[i].second) {
      sum1 += p[i].first;
    }
  }
  int u1 = 1, v1 = 2, u2 = 2, v2 = 3;
  vector<pair<int, int> > pv;
  for (int i = 0; i < m; ++i) {
    pv.push_back({p[i].first, i});
  }
  DSU d;
  sort(pv.begin(), pv.end());
  for (int i = 0; i < m; ++i) {
    int ff = pv[i].first, ss = pv[i].second;
    if (p[ss].second) {
      if (!d.areTeam(u1, v1)) {
        d.mergeTeams(u1, v1);
        sum2 += pv[i].first;
      }
      ans[ss] = {u1, v1++};
    } else {
      if (u2 == v2) {
        u2 = 2;
        v2++;
      }
      if (v2 > n) v2 = n;
      if (!d.areTeam(u2, v2)) {
        d.mergeTeams(u2, v2);
        sum2 += pv[i].first;
      }
      ans[ss] = {u2++, v2};
    }
  }
  if (sum1 == sum2) {
    for (int i = 0; i < m; ++i)
      cout << ans[i].first << ' ' << ans[i].second << endl;
  } else
    cout << -1;
  return 0;
}
