#include <bits/stdc++.h>
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  std::cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
using namespace std;
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) {
    return a.first.second > b.first.second;
  }
  return a.first.first < b.first.first;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j, n, m, k, cnt = 0, ans = 0, t = 1;
  cin >> n >> m;
  vector<pair<pair<long long, long long>, long long> > v;
  for (i = 0; i < m; i++) {
    cin >> k >> j;
    v.push_back(make_pair(make_pair(k, j), i));
  }
  sort(v.begin(), v.end(), cmp);
  if (v[0].first.second == 0 || (n > 2 && v[0].first.second == 0))
    return cout << -1, 0;
  map<long long, pair<long long, long long> > mm;
  k = 1;
  long long f = 1, s = 3, z = 0;
  map<pair<long long, long long>, long long> vis;
  for (i = 0; i < v.size(); i++) {
    if (v[i].first.second == 1) {
      cnt++;
      mm[v[i].second] = make_pair(k, k + 1);
      k++;
    } else {
      z++;
      if (z > (cnt * (cnt + 1)) / 2 - cnt) return cout << -1, 0;
      if (s > k || vis[make_pair(f, s)]) {
        while (1) {
          s++;
          if (s > k) {
            f++;
            if (f > k - 2) f = 1;
            s = f + 2;
          }
          if (!vis[make_pair(f, s)]) break;
        }
      }
      mm[v[i].second] = make_pair(f, s);
      vis[make_pair(f, s)] = 1;
      s++;
    }
  }
  for (auto it : mm) cout << it.second.first << " " << it.second.second << '\n';
  return 0;
}
