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;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 30000;
const int MAXK = 200;
int n, k;
int d[MAXK][MAXN], drt[MAXK];
int rt;
int depth[MAXN];
vector<int> childs[MAXN];
int parent[MAXN];
vector<int> todo[MAXN];
int intodo[MAXN];
int mark[MAXN];
void dfsmark(int at, int val) {
  if (mark[at] != -1)
    return;
  else
    mark[at] = val;
  for (int i = (0); i < (((int)(todo[at]).size())); ++i)
    mark[todo[at][i]] = val;
  for (int i = (0); i < (((int)(childs[at]).size())); ++i)
    dfsmark(childs[at][i], val);
}
void updatetodo(int x) {
  vector<int> ntodo;
  for (int i = (0); i < (((int)(todo[x]).size())); ++i)
    if (intodo[todo[x][i]] == x) ntodo.push_back(todo[x][i]);
  todo[x] = ntodo;
}
bool solve() {
  for (int i = (0); i < (k); ++i) {
    drt[i] = -1;
    for (int j = (0); j < (n); ++j)
      if (d[i][j] == 0)
        if (drt[i] != -1)
          return false;
        else
          drt[i] = j;
    if (drt[i] == -1) return false;
  }
  rt = drt[0];
  for (int j = (0); j < (n); ++j)
    depth[j] = d[0][j], childs[j].clear(), parent[j] = -2, todo[j].clear();
  for (int j = (0); j < (n); ++j)
    if (j != rt) todo[rt].push_back(j), intodo[j] = rt;
  intodo[rt] = -1, parent[rt] = -1;
  for (int i = (1); i < (k); ++i) {
    int crt = drt[i];
    vector<int> path(depth[crt] + 1, -1);
    for (int j = (0); j < (n); ++j)
      if (d[i][j] + depth[j] == depth[crt])
        if (path[depth[j]] != -1)
          return false;
        else
          path[depth[j]] = j;
    for (int k = (0); k < (((int)(path).size())); ++k)
      if (path[k] == -1) return false;
    vector<vector<int> > subtree(depth[crt] + 1);
    for (int j = (0); j < (n); ++j) {
      if ((depth[j] + depth[crt] - d[i][j]) % 2 != 0) return false;
      int dlca = (depth[j] + depth[crt] - d[i][j]) / 2;
      if (dlca < 0 || dlca > depth[crt]) return false;
      if (j != path[dlca]) subtree[dlca].push_back(j);
    }
    int pos = depth[crt];
    while (pos >= 0 && intodo[path[pos]] != -1) --pos;
    if (pos < 0) return false;
    int mrt = path[pos];
    for (int j = (0); j < (n); ++j) mark[j] = -1;
    for (int k = pos; k >= 0; --k) {
      if (intodo[path[k]] != -1) return false;
      if (k != 0 && parent[path[k]] != path[k - 1] ||
          k == 0 && parent[path[k]] != -1)
        return false;
      dfsmark(path[k], path[k]);
    }
    for (int k = (0); k <= (pos); ++k) {
      if (mark[path[k]] != path[k]) return false;
      for (int l = (0); l < (((int)(subtree[k]).size())); ++l) {
        if (mark[subtree[k][l]] != path[k]) return false;
      }
    }
    for (int k = (pos + 1); k < (((int)(path).size())); ++k) {
      if (intodo[path[k]] != mrt) return false;
      intodo[path[k]] = -1;
      parent[path[k]] = path[k - 1];
      childs[path[k - 1]].push_back(path[k]);
      for (int l = (0); l < (((int)(subtree[k]).size())); ++l) {
        if (intodo[subtree[k][l]] != mrt) return false;
        intodo[subtree[k][l]] = path[k];
        todo[path[k]].push_back(subtree[k][l]);
      }
    }
    updatetodo(mrt);
  }
  for (int j = (0); j < (n); ++j)
    if (((int)(todo[j]).size()) > 0) {
      int dmx = depth[j];
      for (int k = (0); k < (((int)(todo[j]).size())); ++k)
        if (depth[todo[j][k]] > dmx) dmx = depth[todo[j][k]];
      vector<int> fst(dmx - depth[j] + 1, -1);
      fst[0] = j;
      for (int k = (0); k < (((int)(todo[j]).size())); ++k) {
        int cur = depth[todo[j][k]] - depth[j];
        if (cur <= 0)
          return false;
        else if (fst[cur] == -1)
          fst[cur] = todo[j][k];
      }
      for (int k = (0); k < (((int)(fst).size())); ++k)
        if (fst[k] == -1) return false;
      for (int k = (0); k < (((int)(todo[j]).size())); ++k) {
        int cur = depth[todo[j][k]] - depth[j];
        parent[todo[j][k]] = fst[cur - 1];
        childs[fst[cur - 1]].push_back(todo[j][k]);
      }
    }
  return true;
}
void run() {
  scanf("%d%d", &n, &k);
  for (int i = (0); i < (k); ++i)
    for (int j = (0); j < (n); ++j) scanf("%d", &d[i][j]);
  if (!solve()) {
    printf("-1\n");
    return;
  }
  for (int i = (0); i < (n); ++i)
    if (parent[i] != -1) printf("%d %d\n", i + 1, parent[i] + 1);
}
int main() {
  run();
  return 0;
}