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;
const int maxn = 30005;
int a[maxn], b[maxn], now[maxn], dep[maxn], fa[maxn], in[maxn], vi[maxn];
int ds[205][maxn], _ds[205][maxn], pt[maxn], ui[maxn], rv[maxn];
vector<int> nxt[maxn];
int n, K;
inline int gn(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  while (dep[u] > dep[v]) u = fa[u];
  while (u != v) u = fa[u], v = fa[v];
  while (u > K) u = fa[u];
  return u;
}
int main() {
  scanf("%d%d", &n, &K);
  for (int i = 1; i <= K; ++i) {
    int p = 0;
    for (int j = 1; j <= n; ++j) {
      scanf("%d", &_ds[i][j]);
      if (!_ds[i][j]) p = j;
    }
    pt[i] = p;
    rv[p] = i;
    ui[p] = 1;
    if (!p) return printf("-1\n"), 0;
  }
  int idx = K;
  vi[1] = now[1] = 1;
  for (int i = 1; i <= n; ++i)
    if (!ui[i]) pt[++idx] = i, rv[i] = idx;
  for (int i = 1; i <= K; ++i)
    for (int j = 1; j <= n; ++j) ds[i][j] = _ds[i][pt[j]];
  for (int i = 1; i <= K; ++i) {
    memset(a, 0, sizeof(a));
    for (int j = 1; j <= n; ++j)
      if (ds[1][j] + ds[i][j] == ds[1][i]) a[ds[1][j]] = j;
    int mx = ds[1][i];
    a[0] = 1;
    for (int j = 1; j <= mx; ++j) {
      if (!a[j] || (fa[a[j]] && fa[a[j]] != a[j - 1])) return printf("-1\n"), 0;
      if (!fa[a[j]]) {
        ++in[a[j - 1]];
        fa[a[j]] = a[j - 1];
        dep[a[j]] = dep[a[j - 1]] + 1;
        vi[a[j]] = 1;
        b[a[j]] = dep[a[j]];
        now[a[j]] = a[j];
      }
    }
  }
  for (int i = 1; i <= K; ++i)
    if (!in[i]) {
      int mx = 0;
      nxt[0].push_back(i);
      for (int j = 1; j <= n; ++j)
        if (ds[i][j] && ds[1][i] + ds[i][j] == ds[1][j]) {
          nxt[ds[i][j]].push_back(j);
          mx = max(mx, ds[i][j]);
        }
      for (int j = 1; j <= mx; ++j) {
        if (!nxt[j].size()) return printf("-1\n"), 0;
        for (int k = 0; k < (int)nxt[j].size(); ++k)
          fa[nxt[j][k]] = nxt[j - 1][0], vi[nxt[j][k]] = 1;
      }
      for (int j = 0; j <= mx; ++j) nxt[j].clear();
    }
  for (int i = 1; i <= n; ++i)
    if (!vi[i]) nxt[ds[1][i]].push_back(i);
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < (int)nxt[i].size(); ++j) {
      int c = nxt[i][j], u = 0, w = 1;
      for (int j = 1; j <= K; ++j)
        if (!u ||
            ds[w][c] + ds[u][c] - ds[w][u] > ds[w][c] + ds[j][c] - ds[w][j])
          u = j;
      if (ds[w][c] + ds[u][c] <= ds[w][u] ||
          (ds[w][c] + ds[u][c] - ds[w][u]) & 1)
        return printf("-1\n", 0);
      int t = u, d = ds[u][c] - ((ds[w][c] + ds[u][c] - ds[w][u]) >> 1);
      while (d--) t = fa[t];
      if (ds[1][c] < b[t]) return printf("-1\n"), 0;
      if (ds[1][c] > b[t]) {
        if (ds[1][c] > b[t] + 1) return printf("-1\n"), 0;
        b[t] = ds[1][c];
        fa[c] = now[t];
        now[t] = c;
      } else
        fa[c] = fa[now[t]];
      vi[c] = 1;
    }
  }
  for (int i = 1; i <= n; ++i)
    if (!vi[i]) return printf("-1\n"), 0;
  for (int i = 2; i <= n; ++i) printf("%d %d\n", pt[fa[i]], pt[i]);
  return 0;
}