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 <typename T>
bool chkmax(T &x, T y) {
  return x < y ? x = y, true : false;
}
template <typename T>
bool chkmin(T &x, T y) {
  return x > y ? x = y, true : false;
}
int readint() {
  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;
}
int n, k, tot;
int d[205][30005], path[205][30005], pt[205], f[30005], v[60005], nxt[60005],
    h[30005], chk[30005];
bool vis[30005];
map<int, int> s[30005];
vector<pair<int, int> > vec[30005];
int getf(int x) { return x == f[x] ? x : f[x] = getf(f[x]); }
void addedge(int x, int y) {
  v[++tot] = y;
  nxt[tot] = h[x];
  h[x] = tot;
  v[++tot] = x;
  nxt[tot] = h[y];
  h[y] = tot;
}
void dfs(int u, int fa) {
  for (int p = h[u]; p; p = nxt[p]) {
    if (v[p] == fa) continue;
    chk[v[p]] = chk[u] + 1;
    dfs(v[p], u);
  }
}
int main() {
  n = readint();
  k = readint();
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= n; j++) d[i][j] = readint();
    for (int j = 1; j <= n; j++)
      if (d[i][j] == 0) pt[i] = j;
    if (!pt[i]) return printf("-1\n"), 0;
  }
  for (int i = 1; i <= n; i++) f[i] = i;
  vis[pt[1]] = 1;
  for (int i = 2; i <= k; i++) {
    for (int j = 1; j <= n; j++) {
      if (pt[1] == j || pt[i] == j) continue;
      if (d[1][j] + d[i][j] == d[1][pt[i]]) path[i][d[1][j]] = j;
    }
    for (int j = 1; j < d[1][pt[i]]; j++)
      if (!path[i][j]) return printf("-1\n"), 0;
    path[i][0] = pt[1], path[i][d[1][pt[i]]] = pt[i];
    for (int j = 0; j < d[1][pt[i]]; j++) {
      if (s[path[i][j]].count(path[i][j + 1])) continue;
      s[path[i][j]][path[i][j + 1]] = 1;
      int fx = getf(path[i][j]), fy = getf(path[i][j + 1]);
      if (fx == fy) return printf("-1\n"), 0;
      f[fx] = fy;
      addedge(path[i][j], path[i][j + 1]);
    }
    for (int j = 1; j <= d[1][pt[i]]; j++) vis[path[i][j]] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    int maxa = 0;
    pair<int, int> opt;
    for (int j = 2; j <= k; j++) {
      int dis = (d[1][i] + d[j][i] - d[1][pt[j]]) / 2;
      if (dis == d[1][i]) continue;
      if (dis < 0 || dis > d[1][i]) return printf("-1\n"), 0;
      vis[i] = 1;
      if (chkmax(maxa, d[1][i] - dis)) opt = make_pair(j, dis);
    }
    if (maxa) vec[path[opt.first][maxa]].push_back(make_pair(opt.second, i));
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) vec[pt[1]].push_back(make_pair(d[1][i], i));
  for (int i = 1; i <= n; i++) {
    sort(vec[i].begin(), vec[i].end());
    pair<int, int> lst0 = make_pair(0, i), lst1 = make_pair(0, 0);
    for (auto r : vec[i]) {
      if (r.first > lst0.first + 1) return printf("-1\n"), 0;
      if (r.first == lst0.first + 1)
        addedge(lst0.second, r.second);
      else if (r.first == lst1.first + 1)
        addedge(lst1.second, r.second);
      if (r.first == lst0.first + 1) lst1 = lst0, lst0 = r;
    }
  }
  for (int i = 1; i <= k; i++) {
    memset(chk, 0, sizeof(chk));
    dfs(pt[i], -1);
    for (int j = 1; j <= n; j++)
      if (chk[j] != d[i][j]) return printf("-1\n"), 0;
  }
  for (int i = 1; i <= n; i++)
    for (int p = h[i]; p; p = nxt[p])
      if (i < v[p]) printf("%d %d\n", i, v[p]);
  return 0;
}