#include <bits/stdc++.h>
using namespace std;
long long n, m, nxt[200005];
pair<long long, long long> ans[200005];
vector<pair<pair<long long, long long>, long long>> edges;
bool cmp(pair<pair<long long, long long>, long long> a,
         pair<pair<long long, long long>, long long> b) {
  if (a.first.first == b.first.first && a.first.second == b.first.second)
    return a.second < b.second;
  if (a.first.first == b.first.first) return a.first.second < b.first.second;
  return a.first.first < b.first.first;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long d, b;
    cin >> d >> b;
    edges.push_back({{d, b ^ 1}, i});
  }
  sort((edges).begin(), (edges).end(), cmp);
  if (edges[0].first.second) return cout << -1 << endl, 0;
  ans[edges[0].second] = {1, 2};
  for (long long i = 1; i <= n; i++) nxt[i] = i + 2;
  long long en = 2, cur = 1;
  for (long long i = 1; i < m; i++) {
    if (!edges[i].first.second) {
      ans[edges[i].second] = {en, en + 1};
      en++;
    } else {
      long long st = cur;
      if (nxt[st] <= en) {
        ans[edges[i].second] = {st, nxt[st]};
        nxt[st]++;
      } else {
        if (cur != en)
          cur++;
        else
          cur = 1;
        while (cur != st && nxt[cur] > en) {
          if (cur != en)
            cur++;
          else
            cur = 1;
        }
        if (cur == st) return cout << -1 << endl, 0;
        ans[edges[i].second] = {cur, nxt[cur]};
        nxt[cur]++;
      }
    }
  }
  for (long long i = 0; i < m; i++)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
