#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int N = 30100;
int rtp[N], rt[N], f[N], d[210][N], ord[N];
vector<int> prt;
int n, k;
map<vector<int>, int> hs;
vector<int> vec[N], e[N];
set<pair<int, int> > E;
set<int> ins;
void fuck(bool op) {
  if (op == 0) {
    puts("-1");
    exit(0);
  }
}
int find(int u) { return f[u] == u ? u : f[u] = find(f[u]); }
void add(int u, int v) {
  if (u > v) swap(u, v);
  if (E.count(make_pair(u + 1, v + 1))) return;
  fuck(find(u) != find(v));
  f[find(u)] = find(v);
  E.insert(make_pair(u + 1, v + 1));
  e[u].push_back(v);
  e[v].push_back(u);
}
void dfs(int u, int f, int dep, int id) {
  fuck(d[id][u] == dep);
  for (auto v : e[u])
    if (v != f) dfs(v, u, dep + 1, id);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) rtp[i] = -1;
  for (int i = 0; i < n; i++) f[i] = i;
  for (int i = 0; i < k; i++) {
    vector<int> r;
    for (int j = 0; j < n; j++) {
      scanf("%d", &d[i][j]);
      if (d[i][j] == 0) r.push_back(j);
    }
    fuck(((int)(r).size()) == 1);
    rt[i] = r[0];
    if (rtp[rt[i]] == -1)
      rtp[rt[i]] = i, prt.push_back(rt[i]);
    else {
      for (int j = 0; j < n; j++) fuck(d[i][j] == d[rtp[rt[i]]][j]);
    }
  }
  int u = prt[0];
  ins.insert(u);
  for (auto v : prt) {
    if (v == u) continue;
    int idu = rtp[u], idv = rtp[v];
    fuck(d[idu][v] == d[idv][u]);
    int dis = d[idu][v];
    for (int i = 0; i < dis + 1; i++) vec[i].clear();
    for (int i = 0; i < n; i++)
      if (d[idu][i] + d[idv][i] == dis) {
        vec[d[idu][i]].push_back(i);
      }
    for (int i = 0; i < dis + 1; i++) fuck(((int)(vec[i]).size()) == 1);
    for (int i = 1; i < dis + 1; i++) {
      int p = vec[i - 1][0], q = vec[i][0];
      add(p, q);
      ins.insert(p);
      ins.insert(q);
    }
  }
  for (auto p : ins) {
    vector<int> it;
    for (int j = 0; j < k; j++) it.push_back(d[j][p]);
    hs[it] = p;
  }
  for (int i = 0; i < n; i++) ord[i] = i;
  sort(ord, ord + n, [&](int u, int v) { return d[0][u] < d[0][v]; });
  for (int i = 0; i < n; i++) {
    int p = ord[i];
    if (ins.count(p)) continue;
    vector<int> it, nit;
    for (int j = 0; j < k; j++) {
      fuck(d[j][p] > 0);
      it.push_back(d[j][p] - 1);
      nit.push_back(d[j][p]);
    }
    fuck(hs.count(it));
    add(hs[it], p);
    hs[nit] = p;
  }
  for (int i = 0; i < k; i++) dfs(rt[i], -1, 0, i);
  for (auto p : E) printf("%d %d\n", p.first, p.second);
}
