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 inf_int = 1e9 + 100;
const long long inf_ll = 1e18;
const double pi = 3.1415926535898;
bool debug = 0;
const int MAXN = 40000 + 100;
const int LOG = 21;
const int mod = 1e9 + 7;
const int MX = (1e6 + 100);
template <class T1, class T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &rhs) {
  out << "( " << rhs.first << " , " << rhs.second << " )";
  return out;
}
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
int n, k;
int d[200][MAXN];
int roots[200];
void bad() {
  cout << -1;
  exit(0);
}
int cnt[MAXN];
void check(int j) {
  for (int i = 0; i <= n; ++i) {
    cnt[i] = 0;
  }
  for (int i = 0; i < n; ++i) {
    cnt[d[j][i]]++;
  }
  if (cnt[0] != 1) {
    bad();
  }
  for (int i = 1; i <= n; ++i) {
    if (cnt[i] && !cnt[i - 1]) bad();
  }
}
int ver[MAXN];
bool used[MAXN];
int par[MAXN];
int h[MAXN];
vector<int> g[MAXN];
vector<int> order[MAXN];
void solve() {
  cin >> n >> k;
  for (int j = 0; j < k; ++j) {
    for (int i = 0; i < n; ++i) {
      cin >> d[j][i];
      if (d[j][i] == 0) {
        roots[j] = i;
      }
    }
    check(j);
  }
  if (k == 1) {
    for (int i = 0; i < n; ++i) {
      ver[d[0][i]] = i;
    }
    for (int i = 0; i < n; ++i) {
      if (i != roots[0]) {
        cout << i + 1 << " " << ver[d[0][i] - 1] + 1 << "\n";
      }
    }
    return;
  }
  for (int j = 1; j < k; ++j) {
    int spec = roots[j];
    memset(h, -1, sizeof h);
    int cnt = 0;
    for (int v = 0; v < n; ++v) {
      if (d[0][v] + d[j][v] == d[0][spec]) {
        used[v] = 1;
        h[d[0][v]] = v;
        cnt++;
      }
    }
    42;
    if (cnt != d[0][spec] + 1) {
      bad();
    }
    for (int i = 1; i < n; ++i) {
      if (h[i] != -1) {
        if (h[i - 1] == -1) {
          bad();
        }
        int v1 = h[i - 1];
        int v2 = h[i];
        par[v2] = v1;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    order[d[0][i]].push_back(i);
  }
  map<vector<int>, int> make_pair, nxt;
  for (int i = 0; i <= n; ++i) {
    nxt.clear();
    for (int v : order[i]) {
      vector<int> val(k - 1);
      for (int j = 1; j < k; ++j) {
        val[j - 1] = d[j][v] - d[0][v];
      }
      42;
      if (used[v]) {
      } else {
        auto it = make_pair.find(val);
        if (it == make_pair.end()) {
          bad();
        }
        par[v] = it->second;
      }
      nxt[val] = v;
    }
    make_pair = nxt;
  }
  for (int i = 0; i < n; ++i) {
    if (i != roots[0]) {
      cout << i + 1 << " " << par[i] + 1 << "\n";
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.precision(15);
  int t = 1;
  while (t--) solve();
  42;
}