#include <bits/stdc++.h>
using namespace std;
int cap[100010];
pair<int, int> out[100010];
vector<pair<pair<int, int>, int> > edge;
vector<pair<pair<int, int>, int> >::iterator it;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, i, j, m, ct = 1, flag = 1;
  cin >> n >> m;
  for (i = 0; i < m; ++i) {
    int temp, in;
    cin >> temp >> in;
    edge.push_back(make_pair(make_pair(temp, -1 * in), i));
  }
  sort(edge.begin(), edge.end());
  pair<int, int> allot = make_pair(2, 2);
  for (it = edge.begin(); it != edge.end(); it++) {
    if (it->first.second == -1) {
      ct++;
      out[it->second] = make_pair(1, ct);
    } else if (it->first.second == 0) {
      if (allot.first == allot.second) {
        if (allot.first < ct) {
          allot.first = 2;
          allot.second++;
        } else {
          flag = 0;
          break;
        }
      }
      out[it->second] = allot;
      allot.first++;
    }
  }
  if (flag == 1) {
    for (i = 0; i < m; ++i)
      cout << out[i].first << " " << out[i].second << '\n';
  } else
    cout << "-1\n";
  return 0;
}
