Problem: Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to him to lend him some cheat papers for this questions and found there the following definition:

The minimum spanning tree T of graph G is such a tree that it contains all the vertices of the original graph G, and the sum of the weights of its edges is the minimum possible among all such trees.

Vladislav drew a graph with n vertices and m edges containing no loops and multiple edges. He found one of its minimum spanning trees and then wrote for each edge its weight and whether it is included in the found tree or not. Unfortunately, the piece of paper where the graph was painted is gone and the teacher is getting very angry and demands to see the original graph. Help Vladislav come up with a graph so that the information about the minimum spanning tree remains correct.

Input

The first line of the input contains two integers n and m (<image>) — the number of vertices and the number of edges in the graph.

Each of the next m lines describes an edge of the graph and consists of two integers aj and bj (1 ≤ aj ≤ 109, bj = {0, 1}). The first of these numbers is the weight of the edge and the second number is equal to 1 if this edge was included in the minimum spanning tree found by Vladislav, or 0 if it was not.

It is guaranteed that exactly n - 1 number {bj} are equal to one and exactly m - n + 1 of them are equal to zero.

Output

If Vladislav has made a mistake and such graph doesn't exist, print  - 1.

Otherwise print m lines. On the j-th line print a pair of vertices (uj, vj) (1 ≤ uj, vj ≤ n, uj ≠ vj), that should be connected by the j-th edge. The edges are numbered in the same order as in the input. The graph, determined by these edges, must be connected, contain no loops or multiple edges and its edges with bj = 1 must define the minimum spanning tree. In case there are multiple possible solutions, print any of them.

Examples

Input

4 5
2 1
3 1
4 0
1 1
5 0


Output

2 4
1 4
3 4
3 1
3 2


Input

3 3
1 0
2 1
3 1


Output

-1

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-10;
const int inf = 2000000000;
int MOD1 = 1000000007;
int MOD2 = 1000000009;
inline bool checkBit(long long int n, long long int i) {
  return n & (1LL << i);
}
inline long long int setBit(long long int n, long long int i) {
  return n | (1LL << i);
  ;
}
inline long long int resetBit(long long int n, long long int i) {
  return n & (~(1LL << i));
}
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline bool isLeapYear(long long int year) {
  return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
inline void normal(long long int &a) {
  a %= 1000000007;
  (a < 0) && (a += 1000000007);
}
inline long long int modMul(long long int a, long long int b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  return (a * b) % 1000000007;
}
inline long long int modAdd(long long int a, long long int b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  return (a + b) % 1000000007;
}
inline long long int modSub(long long int a, long long int b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline long long int modPow(long long int b, long long int p) {
  long long int r = 1LL;
  while (p) {
    if (p & 1) r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1LL;
  }
  return r;
}
inline long long int modDiv(long long int a, long long int b) {
  return modMul(a, modPow(b, 1000000007 - 2));
}
bool comp(const pair<pair<long long int, long long int>, long long int> &p1,
          const pair<pair<long long int, long long int>, long long int> &p2) {
  if (p1.first.second == p2.first.second) {
    return p1.first.first < p2.first.first;
  }
  return p1.first.second > p2.first.second;
}
bool comp2(const pair<pair<long long int, long long int>, long long int> &p1,
           const pair<pair<long long int, long long int>, long long int> &p2) {
  if (p1.first.second == p2.first.second) {
    return p1.first.first > p2.first.first;
  }
  return p1.first.second > p2.first.second;
}
long long int converter(string a) {
  long long int i, mul = 1, r, t, ans = 0LL;
  if (a.length() == 0) return 0;
  for (i = a.length() - 1; i >= 0; i--) {
    t = a[i] - '0';
    r = t % 10;
    ans += (mul * r);
    mul = mul * 10;
  }
  return ans;
}
pair<pair<long long int, long long int>, long long int> store[100005];
vector<pair<long long int, pair<long long int, long long int> > > ans;
vector<pair<long long int, long long int> > ed;
long long int got[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, m, i, w, mxima = 0;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    long long int w, taken;
    cin >> w >> taken;
    store[i] = make_pair(make_pair(w, taken), i);
  }
  sort(store + 1, store + m + 1, comp);
  long long int x = 1;
  long long int y = 2;
  for (i = 1; i <= n - 1; i++) {
    w = store[i].first.first;
    ans.push_back(make_pair(store[i].second, make_pair(x, y)));
    got[y] = w;
    x = y;
    y++;
  }
  long long int cnt = 0;
  long long int tempx, tempy = 3;
  while (cnt < (m - (n - 1))) {
    tempx = 1;
    while ((tempy - tempx) >= 2 && cnt < (m - (n - 1))) {
      ed.push_back(make_pair(tempx, tempy));
      tempx++;
      cnt++;
    }
    tempy++;
  }
  long long int j = 0;
  for (i = n; i <= m; i++) {
    if (j >= ed.size()) continue;
    x = ed[j].first;
    y = ed[j].second;
    w = store[i].first.first;
    if (got[y] <= w) ans.push_back(make_pair(store[i].second, make_pair(x, y)));
    j++;
  }
  if (ans.size() < m) {
    cout << "-1";
    return 0;
  }
  sort(ans.begin(), ans.end());
  for (i = 0; i < m; i++) {
    cout << ans[i].second.first << " " << ans[i].second.second << '\n';
  }
  return 0;
}