#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;
}
