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>
int F() {
  register int a, b, c;
  while (c = getchar(), c < '-')
    ;
  b = (c == '-');
  for (a = b ? 0 : c - '0'; c = getchar(), c > '-'; a = a * 10 + c - '0')
    ;
  return b ? -a : a;
}
const int N = 30001, K = 200;
int n, k, d[K][N], id[K], len[N], p[N], dep[N], fa[N], head[N], to[N << 1],
    next[N << 1], e = 2;
bool vis[N];
std::multimap<int, int> map[N];
std::set<std::pair<int, int> > eset;
std::vector<int> belong[K];
int find(register int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
bool connect(register int u, register int v) {
  if (find(u) == find(v))
    return eset.find(std::make_pair(u, v)) != eset.end() ||
           eset.find(std::make_pair(v, u)) != eset.end();
  fa[fa[u]] = fa[v];
  to[e] = v, next[e] = head[u], head[u] = e++;
  to[e] = u, next[e] = head[v], head[v] = e++;
  eset.insert(std::make_pair(u, v));
  return 1;
}
int q[N], dist[N];
void bfs(register int x) {
  register int l = -1, r = -1, i;
  memset(dist + 1, -1, n * sizeof(int));
  dist[q[++r] = x] = 0;
  while (l++ < r) {
    for (i = head[x = q[l]]; i; i = next[i]) {
      if (dist[to[i]] == -1) {
        dist[q[++r] = to[i]] = dist[x] + 1;
      }
    }
  }
}
int main() {
  register int i, j;
  n = F(), k = F();
  for (i = 1; i <= n; ++i) fa[i] = i;
  for (i = 0; i < k; ++i)
    for (j = 1; j <= n; ++j) {
      d[i][j] = F();
      if (d[i][j] == 0) {
        if (id[i] != 0) {
          puts("-1");
          return 0;
        }
        id[i] = j;
      }
    }
  if (k != 1) {
    for (i = 1; i <= n; ++i) {
      register int min = 2 * n, cho, cur;
      for (j = 1; j < k; ++j) {
        cur = d[0][i] + d[j][i] - d[0][id[j]];
        if (cur % 2 != 0) {
          puts("-1");
          return 0;
        }
        if (cur < min) min = cur, cho = j;
      }
      belong[cho].push_back(i);
      len[i] = min / 2;
    }
    for (i = 1; i < k; ++i) {
      memset(p, 0, sizeof(int) * n);
      for (j = 1; j <= n; ++j)
        if (d[0][j] + d[i][j] == d[0][id[i]]) {
          if (p[d[0][j]] != 0) {
            puts("-1");
            return 0;
          }
          vis[p[d[0][j]] = j] = 1;
        }
      for (j = 0; j < d[0][id[i]]; ++j) {
        if (!connect(p[j], p[j + 1])) {
          puts("-1");
          return 0;
        }
      }
      for (j = 0; j < belong[i].size(); ++j) {
        register int q = belong[i][j];
        if (len[q] == 0) continue;
        if (d[0][q] < len[q]) {
          puts("-1");
          return 0;
        }
        map[p[d[0][q] - len[q]]].insert(std::make_pair(len[q], q));
      }
    }
  } else {
    vis[id[0]] = 1;
    for (i = 1; i <= n; ++i) map[id[0]].insert(std::make_pair(d[0][i], i));
  }
  for (i = 1; i <= n; ++i)
    if (vis[i]) {
      p[0] = i;
      register int last = 0;
      for (register std::map<int, int>::iterator it = map[i].begin();
           it != map[i].end(); ++it) {
        if (it->first == 0) continue;
        if (it->first > last + 1) {
          puts("-1");
          return 0;
        }
        if (!connect(p[it->first - 1], p[last = it->first] = it->second)) {
          puts("-1");
          return 0;
        }
      }
    }
  if (e != 2 * n) {
    puts("-1");
    return 0;
  }
  for (i = 0; i < k; ++i) {
    bfs(id[i]);
    for (j = 1; j <= n; ++j)
      if (dist[j] != d[i][j]) {
        puts("-1");
        return 0;
      }
  }
  for (i = 2; i < e; i += 2) printf("%d %d\n", to[i], to[i ^ 1]);
  fclose(stdin);
  fclose(stdout);
  return 0;
}