Problem: Petya had a tree consisting of n vertices numbered with integers from 1 to n. Accidentally he lost his tree. 

Petya remembers information about k vertices: distances from each of them to each of the n tree vertices.

Your task is to restore any tree that satisfies the information that Petya remembers or report that such tree doesn't exist.

Input

The first line contains two integers n and k (2 ≤ n ≤ 30 000, 1 ≤ k ≤ min(200, n)) — the number of vertices in the tree and the number of vertices about which Petya remembers distance information.

The following k lines contain remembered information. The i-th line contains n integers di, 1, di, 2, ..., di, n (0 ≤ di, j ≤ n - 1), where di, j — the distance to j-th vertex from the i-th vertex that Petya remembers.

Output

If there are no suitable trees, print -1.

In the other case, print n - 1 lines: each line should contain two vertices connected by edge in the required tree. You can print edges and vertices in an edge in any order. The tree vertices are enumerated from 1 to n.

If there are many solutions print any of them.

Examples

Input

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


Output

2 1
3 2
4 3
5 2


Input

3 1
1 2 1


Output

-1

Note

Picture for the first sample:

<image>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
vector<pair<int, int>> output;
const int nax = 30123;
vector<int> w_ans[nax];
void add_edge(int a, int b) {
  debug() << " ["
          << "a"
             ": "
          << (a)
          << "] "
             " ["
          << "b"
             ": "
          << (b) << "] ";
  w_ans[a].push_back(b);
  w_ans[b].push_back(a);
  output.push_back({a + 1, b + 1});
}
void NO() {
  puts("-1");
  exit(0);
}
int n, k;
vector<vector<int>> input;
vector<int> where_zero;
void rec(const vector<vector<int>>& tree, int which_line) {
  debug() << "rec"
             " ["
          << "tree"
             ": "
          << (tree)
          << "] "
             " ["
          << "which_line"
             ": "
          << (which_line) << "] ";
  assert(!tree.empty());
  assert((int)tree[0].size() == 1);
  for (const vector<int>& row : tree)
    if (row.empty()) NO();
  if (which_line == k) {
    for (int i = 1; i < (int)tree.size(); ++i)
      for (int x : tree[i]) add_edge(tree[i - 1][0], x);
    return;
  }
  const int spec = where_zero[which_line];
  int depth = -1;
  for (int d = 0; d < (int)tree.size(); ++d)
    for (int x : tree[d])
      if (x == spec) depth = d;
  if (depth == -1) {
    rec(tree, which_line + 1);
    return;
  }
  vector<vector<vector<int>>> new_trees;
  for (int h = 0; h < (int)tree.size(); ++h)
    for (int x : tree[h]) {
      int dist = input[which_line][x];
      int lca = h + depth - dist;
      if (lca % 2) NO();
      lca /= 2;
      debug() << " ["
              << "lca"
                 ": "
              << (lca) << "] ";
      if (!(0 <= lca && lca < n)) NO();
      if ((int)new_trees.size() <= lca) new_trees.push_back({});
      if ((int)new_trees.size() <= lca) NO();
      vector<vector<int>>& that_tree = new_trees[lca];
      int how = h - lca;
      if ((int)that_tree.size() <= how) that_tree.push_back({});
      if ((int)that_tree.size() <= how) NO();
      that_tree[how].push_back(x);
    }
  for (const vector<vector<int>>& tr : new_trees)
    if (tr.empty() || tr[0].empty()) NO();
  for (int i = 1; i < (int)new_trees.size(); ++i) {
    add_edge(new_trees[i][0][0], new_trees[i - 1][0][0]);
  }
  for (const auto& xx : new_trees) rec(xx, which_line + 1);
}
void dfs(int a, int par, int so_far, const vector<int>& should) {
  debug() << "dfs"
             " ["
          << "a"
             ": "
          << (a)
          << "] "
             " ["
          << "par"
             ": "
          << (par)
          << "] "
             " ["
          << "so_far"
             ": "
          << (so_far)
          << "] "
             " ["
          << "should"
             ": "
          << (should) << "] ";
  if (so_far != should[a]) NO();
  for (int b : w_ans[a])
    if (b != par) dfs(b, a, so_far + 1, should);
}
int main() {
  scanf("%d%d", &n, &k);
  input.resize(k, vector<int>(n));
  where_zero.resize(k);
  for (int which = 0; which < k; ++which) {
    vector<int>& line = input[which];
    int zeros = 0;
    for (int i = 0; i < n; ++i) {
      scanf("%d", &line[i]);
      if (line[i] == 0) {
        ++zeros;
        where_zero[which] = i;
      }
    }
    if (zeros != 1) NO();
  }
  vector<vector<int>> tree;
  for (int i = 0; i < n; ++i) {
    int v = input[0][i];
    while ((int)tree.size() <= v) tree.push_back({});
    tree[v].push_back(i);
  }
  debug() << " ["
          << "tree"
             ": "
          << (tree) << "] ";
  rec(tree, 1);
  for (int i = 0; i < k; ++i) dfs(where_zero[i], -1, 0, input[i]);
  for (pair<int, int> p : output) printf("%d %d\n", p.first, p.second);
}