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;
struct node {
  int l;
  int r;
  int p;
  int c;
  int len;
};
node nodes[200010];
int n, m, message, tot, landlords, match[200010];
inline void R(int &v) {
  v = 0;
  char c = 0;
  int p = 1;
  while (c < '0' || c > '9') {
    if (c == '-') p = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    v = (v << 3) + (v << 1) + c - '0';
    c = getchar();
  }
  v *= p;
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline int getint() {
  int _b = 0;
  char _c;
  for (_c = getchar(); _c < '0' || _c > '9'; _c = getchar())
    ;
  for (; _c >= '0' && _c <= '9'; _c = getchar()) {
    _b = (_b << 3) + (_b << 1);
    _b += _c - '0';
  }
  return _b;
}
inline int exgetint() {
  int _b = 0;
  char _c;
  int _p = 1;
  for (_c = getchar(); (_c < '0' || _c > '9') && _c != '-'; _c = getchar())
    ;
  if (_c == '-') {
    _c = getchar();
    _p = -1;
  }
  for (; _c >= '0' && _c <= '9'; _c = getchar()) {
    _b = (_b << 3) + (_b << 1);
    _b += _c - '0';
  }
  return _p * _b;
}
void calc() {
  message = 1, tot = 1, landlords = 1;
  for (int i = 1; i <= m; i++) {
    if (nodes[i].c == 1) {
      if (message >= n)
        printf("-1"), exit(0);
      else
        nodes[i].l = message, nodes[i].r = message + 1, message++, tot++;
      landlords = 1;
    }
    if (nodes[i].c == 0) {
      if (tot <= 2) printf("-1"), exit(0);
      if ((landlords == tot - 2 && match[landlords] == tot) ||
          (landlords > tot - 2)) {
        printf("-1");
        exit(0);
      }
      if (match[landlords] < tot) {
        if (match[landlords] == 0)
          match[landlords] = landlords + 2;
        else
          match[landlords] = match[landlords] + 1;
        nodes[i].l = landlords, nodes[i].r = match[landlords];
        if (match[landlords] == tot) landlords++;
      }
    }
  }
}
inline int Read() {
  int p = 1, x;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') p = -1;
  x = c - '0';
  while ((c = getchar()) > '0' && c <= '9') x = x * 10 + c - '0';
  x *= p;
  return x;
}
inline int READ() {
  char ch;
  bool flag = false;
  int a = 0;
  while (!((((ch = getchar()) >= '0') && (ch <= '9')) || (ch == '-')))
    ;
  if (ch != '-') {
    a *= 10;
    a += ch - '0';
  } else {
    flag = true;
  }
  while (((ch = getchar()) >= '0') && (ch <= '9')) {
    a *= 10;
    a += ch - '0';
  }
  if (flag) {
    a = -a;
  }
  return a;
}
void WRITE(int a) {
  if (a < 0) {
    putchar('-');
    a = -a;
  }
  if (a >= 10) {
    WRITE(a / 10);
  }
  putchar(a % 10 + '0');
}
bool comp1(const node &x, const node &y) {
  if (x.len != y.len) return x.len < y.len;
  return x.c > y.c;
}
bool comp2(const node &x, const node &y) { return x.p < y.p; }
template <typename T>
class Treap {
 public:
  int tot;
  int root;
  int ls[300010], rs[300010], fnodes[300010], priority[300010], size[300010],
      num[300010];
  T val[300010];
  Treap() {
    tot = 2;
    root = 1;
    val[1] = 1000000000 + 1;
    val[2] = -1000000000 - 1;
    ls[1] = 2;
    fnodes[2] = 1;
    size[1] = 2;
    size[2] = 1;
    priority[1] = priority[2] = 1000000000 + 1;
    num[1] = num[2] = 1;
  }
  int newnode() {
    ++tot;
    priority[tot] = rand();
    size[tot] = 1;
    num[tot] = 1;
    return tot;
  }
  int begin() { return 2; }
  int end() { return 1; }
  int next(int now) {
    if (rs[now] != 0) {
      int x = rs[now];
      while (ls[x] != 0) x = ls[x];
      return x;
    }
    while (rs[fnodes[now]] == now) now = fnodes[now];
    return fnodes[now];
  }
  int prev(int now) {
    if (ls[now] != 0) {
      int x = ls[now];
      while (rs[x] != 0) x = rs[x];
      return x;
    }
    while (ls[fnodes[now]] == now) now = fnodes[now];
    return fnodes[now];
  }
  void _dfs(int now) {
    if (ls[now] != 0) _dfs(ls[now]);
    cout << val[now] << endl;
    if (rs[now] != 0) _dfs(rs[now]);
  }
  void update(int now) { size[now] = size[ls[now]] + size[rs[now]] + num[now]; }
  void left_rotate(int now) {
    if (now == root) return;
    int f = fnodes[now], ff = fnodes[fnodes[now]], b = ls[now];
    if (f == root) {
      root = now;
      ls[now] = f;
      fnodes[f] = now;
      rs[f] = b;
      if (b != 0) fnodes[b] = f;
    } else {
      fnodes[now] = ff;
      if (ls[ff] == f)
        ls[ff] = now;
      else
        rs[ff] = now;
      ls[now] = f;
      fnodes[f] = now;
      rs[f] = b;
      if (b != 0) fnodes[b] = f;
    }
    update(f), update(now);
  }
  void right_rotate(int now) {
    if (now == root) return;
    int f = fnodes[now], ff = fnodes[fnodes[now]], b = rs[now];
    if (f == root) {
      root = now;
      rs[now] = f;
      fnodes[f] = now;
      ls[f] = b;
      if (b != 0) fnodes[b] = f;
    } else {
      fnodes[now] = ff;
      if (ls[ff] == f)
        ls[ff] = now;
      else
        rs[ff] = now;
      rs[now] = f;
      fnodes[f] = now;
      ls[f] = b;
      if (b != 0) fnodes[b] = f;
    }
    update(f), update(now);
  }
  void _insert(int now, T x) {
    if (x == val[now]) {
      num[now]++;
      update(now);
      return;
    }
    if (x < val[now]) {
      if (ls[now] != 0)
        _insert(ls[now], x);
      else {
        ls[now] = newnode();
        fnodes[tot] = now;
        val[tot] = x;
      }
      if (priority[now] > priority[ls[now]]) right_rotate(ls[now]);
    } else {
      if (rs[now] != 0)
        _insert(rs[now], x);
      else {
        rs[now] = newnode();
        fnodes[tot] = now;
        val[tot] = x;
      }
      if (priority[now] > priority[rs[now]]) left_rotate(rs[now]);
    }
    update(now);
  }
  void down(int now) {
    while (ls[now] != 0 || rs[now] != 0) {
      if (ls[now] == 0)
        left_rotate(rs[now]);
      else if (rs[now] == 0)
        right_rotate(ls[now]);
      else {
        if (priority[ls[now]] < priority[rs[now]])
          right_rotate(ls[now]);
        else
          left_rotate(rs[now]);
      }
    }
    int f = fnodes[now];
    if (ls[f] == now) ls[f] = 0;
    if (rs[f] == now) rs[f] = 0;
    while (f != root) update(f), f = fnodes[f];
  }
  void _erase(int now, T x) {
    if (now == 0) return;
    if (val[now] == x) {
      num[now]--;
      if (num[now] == 0)
        down(now);
      else
        update(now);
      return;
    }
    if (x < val[now])
      _erase(ls[now], x);
    else
      _erase(rs[now], x);
    update(now);
  }
  T _findkth(int now, int kth) {
    if (size[ls[now]] >= kth) return _findkth(ls[now], kth);
    int s = kth - size[ls[now]] - num[now];
    if (s <= 0) return val[now];
    return _findkth(rs[now], s);
  }
  int _calc(int now, T x) {
    if (now == 0) return 0;
    if (x < val[now]) return _calc(ls[now], x);
    if (x == val[now]) return size[ls[now]];
    return _calc(rs[now], x) + size[ls[now]] + num[now];
  }
  int _find(int now, T x) {
    if (now == 0) return -1;
    if (x < val[now]) {
      int ret = _find(ls[now], x);
      if (ret == -1) return prev(now);
      return ret;
    }
    if (x == val[now]) return now;
    if (x > val[now]) {
      int ret = _find(rs[now], x);
      if (ret == -1) return now;
      return ret;
    }
  }
  void insert(T x) { _insert(root, x); }
  void erase(T x) { _erase(root, x); }
  T findkth(int x) {
    if (x < 0) return -1;
    if (x > size[root] - 2) return -1;
    return _findkth(root, x + 1);
  }
  int calc(T x) { return _calc(root, x) - 1; }
  T findmin(T x) {
    int s = _find(root, x);
    if (val[s] == x) s = prev(s);
    if (val[s] <= -1000000000) return -1;
    return val[s];
  }
  T findmax(T x) {
    int s = _find(root, x);
    if (val[s] <= x) s = next(s);
    if (val[s] >= 1000000000) return -1;
    return val[s];
  }
  int find(T x) { return _find(root, x); }
  void sort() { _dfs(root); }
};
void init() {
  n = getint(), m = getint();
  for (int i = 1; i <= m; i++) {
    nodes[i].len = getint();
    nodes[i].c = getint();
    nodes[i].p = i;
  }
  sort(nodes + 1, nodes + m + 1, comp1);
}
int main() {
  init();
  calc();
  if (message < n) printf("-1"), exit(0);
  sort(nodes + 1, nodes + m + 1, comp2);
  for (int i = 1; i <= m; i++) printf("%d %d\n", nodes[i].l, nodes[i].r);
  return 0;
}