#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
pair<long long, long long> ans[100009];
long long vis[100009], acys[100009];
pair<pair<long long, long long>, long long> arr[100009];
vector<pair<long long, long long> > adj[100009];
bool cmp(pair<pair<long long, long long>, long long> l,
         pair<pair<long long, long long>, long long> r) {
  if (l.first.first == r.first.first) return (l.first.second > r.first.second);
  return (l.first.first < r.first.first);
}
long long mst() {
  long long jog = 0;
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      q;
  q.push(make_pair(0, 1));
  while (!q.empty()) {
    long long nd = q.top().second;
    long long cost = q.top().first;
    q.pop();
    if (vis[nd]) continue;
    vis[nd] = 1;
    jog += cost;
    for (long long i = 0; i < adj[nd].size(); i++) {
      long long v = adj[nd][i].first, w = adj[nd][i].second;
      if (!vis[v]) q.push(make_pair(w, v));
    }
  }
  return jog;
}
int main() {
  long long a, b;
  cin >> a >> b;
  for (long long i = 0; i < b; i++)
    cin >> arr[i].first.first >> arr[i].first.second,
        arr[i].second = i, acys[i] = arr[i].first.first;
  sort(arr, arr + b);
  long long sum = 0;
  long long yol = 1, road = 2;
  for (long long i = 0; i < b; i++)
    if (arr[i].first.second == 1) {
      ans[arr[i].second] = make_pair(yol, road);
      sum += arr[i].first.first;
      road++;
      if (road > a) yol++, road = yol + 1;
    }
  road = 3, yol = 2;
  for (long long i = 0; i < b; i++)
    if (arr[i].first.second == 0) {
      ans[arr[i].second] = make_pair(yol, road);
      yol++;
      if (yol == road) road++, yol = 2;
    }
  for (long long i = 0; i < b; i++)
    adj[ans[i].first].push_back(make_pair(ans[i].second, acys[i])),
        adj[ans[i].second].push_back(make_pair(ans[i].first, acys[i]));
  if (mst() == sum)
    for (long long i = 0; i < b; i++)
      cout << ans[i].first << " " << ans[i].second << endl;
  else
    cout << "-1" << endl;
  return 0;
}
