#include <bits/stdc++.h>   using namespace std;   const int N = 3e4 + 7, M = 2e2 + 7;   bool fl[N];   int n, k, tot, fs[N], sum[N], pos[M], f[M][N];   map<int, bool> s[N];   struct edge {     int u, v;   } ed[N * M];   struct node {     int ch[M], num;   } qt[N];   inline int read() {     int num = 0;     char g = getchar();     while (g < 48 || 57 < g) g = getchar();     while (47 < g && g < 58)       num = (num << 1) + (num << 3) + g - 48, g = getchar();     return num;   }   inline int find(int u) {     if (fs[u] == u) return u;     return fs[u] = find(fs[u]);   }   inline bool equals(node a, node b) {     for (int i = 1; i <= k; i++)       if (a.ch[i] + 1 != b.ch[i]) return false;     return true;   }   inline bool cmp(node a, node b) {     for (int i = 1; i <= k; i++) {       if (a.ch[i] < b.ch[i]) return false;       if (a.ch[i] > b.ch[i]) return true;     }     return false;   }   int main() {     n = read(), k = read();     for (int i = 1; i <= k; i++)       for (int x = 1; x <= n; x++) f[i][x] = read();     for (int i = 1; i <= k; i++)       for (int x = 1; x <= n; x++)         if (!f[i][x]) pos[i] = x;     for (int i = 2; i <= k; i++) {       memset(sum, 0, sizeof(sum));       for (int c = 1; c <= n; c++)         if (f[i][c] + f[1][c] == f[1][pos[i]]) sum[f[1][c]] = c;       for (int c = 0; c <= f[1][pos[i]]; c++)         if (!sum[c]) {           puts( -1 );           return 0;         }       for (int c = 0; c < f[1][pos[i]]; c++)         if (!s[sum[c]][sum[c + 1]])           s[sum[c]][sum[c + 1]] = s[sum[c + 1]][sum[c]] = 1, ed[++tot].u = sum[c],                             ed[tot].v = sum[c + 1];     }     for (int i = 1; i <= n; i++) fs[i] = i;     for (int i = 1; i <= tot; i++) {       int a = ed[i].u, b = ed[i].v;       fl[a] = fl[b] = 1, fs[a] = find(a), fs[b] = find(b);       if (fs[a] == fs[b]) {         puts( -1 );         return 0;       }       fs[fs[a]] = find(b);     }     int tp = 1;     for (int x = 1; x <= n; x++) {       qt[x].num = x;       for (int i = 1; i <= k; i++) qt[x].ch[i] = f[i][x];     }     for (int i = 1; i <= k; i++) fl[pos[i]] = 1;     sort(qt + 1, qt + n + 1, cmp);     for (int i = 1; i <= n; i++) {       int c = qt[i].num;       if (fl[c]) continue;       while ((!equals(qt[tp], qt[i])) && tp <= n) tp++;       if (tp > n) {         puts( -1 );         return 0;       }       tot++, ed[tot].u = c, ed[tot].v = qt[tp].num;     }     for (int i = 1; i <= tot; i++) printf( %d %d n , ed[i].u, ed[i].v);     return 0;   }   