#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
pair<pair<int, int>, int> a[maxn];
pair<int, int> ans[maxn];
bool cmp(pair<pair<int, int>, int> i, pair<pair<int, int>, int> j) {
  if (i.first.first != j.first.first) return (i.first.first < j.first.first);
  return (i.first.second > j.first.second);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    pair<int, int> tmp;
    cin >> tmp.first >> tmp.second;
    a[i] = make_pair(tmp, i);
  }
  sort(a + 1, a + m + 1, cmp);
  int last = 1;
  int cnt = 0;
  pair<int, int> cur = make_pair(3, 2);
  for (int i = 1; i <= m; i++)
    if (a[i].first.second) {
      last++;
      ans[a[i].second] = make_pair(1, last);
      cnt += last - 2;
    } else {
      if (!cnt) {
        cout << "-1\n";
        return 0;
      }
      cnt--;
      ans[a[i].second] = cur;
      if (cur.second != cur.first - 1) {
        cur.second++;
      } else {
        cur.first++;
        cur.second = 2;
      }
    }
  for (int i = 1; i <= m; i++)
    cout << ans[i].first << " " << ans[i].second << "\n";
}
