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 MOD = 1000000007;
const int UNDEF = -1;
const int INF = 1 << 29;
template <typename T>
inline bool chkmax(T &aa, T bb) {
  return aa < bb ? aa = bb, true : false;
}
template <typename T>
inline bool chkmin(T &aa, T bb) {
  return aa > bb ? aa = bb, true : false;
}
int rint();
char rch();
long long rlong();
void fail() {
  printf("-1\n");
  exit(0);
}
const int mk = 200, mn = 30000;
vector<int> gans[mn];
int vbfsdist[mn];
void bfs(int n, int init) {
  for (int x = 0; x < n; x++) vbfsdist[x] = INF;
  vbfsdist[init] = 0;
  queue<int> q;
  q.push(init);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    int cand = vbfsdist[x] + 1;
    for (auto &y : gans[x]) {
      if (cand < vbfsdist[y]) {
        vbfsdist[y] = cand;
        q.push(y);
      }
    }
  }
}
void ae(int x, int y) {
  gans[x].push_back(y);
  gans[y].push_back(x);
}
int vinp[mk][mn];
int vd[mn][mk];
int vspec[mk];
vector<int> d2v[mn];
bitset<mk> vb[mn];
int vlo[2][mn];
int perm[mn];
int iperm[mn];
bitset<mn> specced;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n = rint(), k = rint();
  for (int i = 0; i < k; i++) {
    int x = -1;
    for (int j = 0; j < n; j++) {
      int got = rint();
      vinp[i][j] = got;
      if (got == 0) x = j;
    }
    if (x == -1) fail();
    perm[x] = i;
    iperm[i] = x;
    specced[x] = true;
  }
  {
    int idx = k;
    for (int x = 0; x < n; x++) {
      if (!specced[x]) {
        iperm[idx] = x;
        perm[x] = idx;
        idx++;
      }
    }
  }
  for (int x = 0; x < k; x++) {
    for (int y = 0; y < n; y++) {
      vd[perm[y]][x] = vinp[x][y];
    }
  }
  int kk = k - 1;
  for (int x = 0; x < n; x++) {
    d2v[vd[x][kk]].push_back(x);
  }
  int cur = 0, nxt = 1;
  {
    bitset<mk> bs;
    for (int i = 0; i < kk; i++) bs[i] = true;
    vb[kk] = bs;
    for (int t = 0; t < kk; t++) vlo[cur][t] = vd[kk][t];
  }
  for (int d = 1; d < n; d++) {
    memcpy(vlo[nxt], vlo[cur], sizeof vlo[cur]);
    for (auto &x : d2v[d]) {
      bitset<mk> bs;
      for (int t = 0; t < kk; t++) {
        int got = vd[x][t], lo = vlo[cur][t];
        if (got < lo) {
          bs[t] = true;
          chkmin(vlo[nxt][t], got);
        }
        vb[x] = bs;
      }
      int parent = -1;
      for (auto &p : d2v[d - 1]) {
        if ((bs & vb[p]) == bs) {
          bool good = true;
          for (int t = 0; t < kk; t++) {
            int gotx = vd[x][t];
            int gotp = vd[p][t];
            bool ok;
            if (bs[t])
              ok = (gotx == gotp - 1);
            else
              ok = (gotx == gotp + 1);
            if (!ok) {
              good = false;
              break;
            }
          }
          if (good) {
            parent = p;
            break;
          }
        }
      }
      if (parent == -1) {
        for (auto &p : d2v[d - 1]) {
          bool good = true;
          for (int t = 0; t < kk; t++) {
            int gotx = vd[x][t];
            int gotp = vd[p][t];
            if (gotx != gotp + 1) {
              good = false;
              break;
            }
          }
          if (good) {
            parent = p;
            break;
          }
        }
      }
      if (parent == -1) fail();
      ae(parent, x);
    }
    swap(cur, nxt);
  }
  for (int t = 0; t < k; t++) {
    bfs(n, t);
    for (int y = 0; y < n; y++) {
      if (vbfsdist[y] != vd[y][t]) {
        fail();
      }
    }
  }
  for (int x = 0; x < n; x++) {
    for (auto &y : gans[x]) {
      if (x < y) printf("%d %d\n", iperm[x] + 1, iperm[y] + 1);
    }
  }
}
static char stdinBuffer[1024];
static char *stdinDataEnd = stdinBuffer + sizeof(stdinBuffer);
static const char *stdinPos = stdinDataEnd;
void readAhead(size_t amount) {
  size_t remaining = stdinDataEnd - stdinPos;
  if (remaining < amount) {
    memmove(stdinBuffer, stdinPos, remaining);
    size_t sz = fread(stdinBuffer + remaining, 1,
                      sizeof(stdinBuffer) - remaining, stdin);
    stdinPos = stdinBuffer;
    stdinDataEnd = stdinBuffer + remaining + sz;
    if (stdinDataEnd != stdinBuffer + sizeof(stdinBuffer)) *stdinDataEnd = 0;
  }
}
int rint() {
  readAhead(16);
  int x = 0;
  bool neg = false;
  while (*stdinPos == ' ' || *stdinPos == '\n') ++stdinPos;
  if (*stdinPos == '-') {
    ++stdinPos;
    neg = true;
  }
  while (*stdinPos >= '0' && *stdinPos <= '9') {
    x *= 10;
    x += *stdinPos - '0';
    ++stdinPos;
  }
  return neg ? -x : x;
}
char rch() {
  readAhead(16);
  while (*stdinPos == ' ' || *stdinPos == '\n') ++stdinPos;
  char ans = *stdinPos;
  ++stdinPos;
  return ans;
}
long long rlong() {
  readAhead(32);
  long long x = 0;
  bool neg = false;
  while (*stdinPos == ' ' || *stdinPos == '\n') ++stdinPos;
  if (*stdinPos == '-') {
    ++stdinPos;
    neg = true;
  }
  while (*stdinPos >= '0' && *stdinPos <= '9') {
    x *= 10;
    x += *stdinPos - '0';
    ++stdinPos;
  }
  return neg ? -x : x;
}