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;
using ll = long long;
template <class t, class u>
void chmax(t& first, u second) {
  if (first < second) first = second;
}
template <class t, class u>
void chmin(t& first, u second) {
  if (second < first) first = second;
}
template <class t>
using vc = vector<t>;
template <class t>
using vvc = vc<vc<t>>;
using pi = pair<int, int>;
using vi = vc<int>;
template <class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
  return os << "{" << p.first << "," << p.second << "}";
}
template <class t>
ostream& operator<<(ostream& os, const vc<t>& v) {
  os << "{";
  for (auto e : v) os << e << ",";
  return os << "}";
}
using uint = unsigned;
using ull = unsigned long long;
template <class t, size_t n>
ostream& operator<<(ostream& os, const array<t, n>& first) {
  return os << vc<t>(first.begin(), first.end());
}
template <int i, class T>
void print_tuple(ostream&, const T&) {}
template <int i, class T, class H, class... Args>
void print_tuple(ostream& os, const T& t) {
  if (i) os << ",";
  os << get<i>(t);
  print_tuple<i + 1, T, Args...>(os, t);
}
template <class... Args>
ostream& operator<<(ostream& os, const tuple<Args...>& t) {
  os << "{";
  print_tuple<0, tuple<Args...>, Args...>(os, t);
  return os << "}";
}
template <class t>
void print(t x, int suc = 1) {
  cout << x;
  if (suc == 1) cout << "\n";
  if (suc == 2) cout << " ";
}
ll read() {
  ll i;
  cin >> i;
  return i;
}
vi readvi(int n, int off = 0) {
  vi v(n);
  for (int i = int(0); i < int(n); i++) v[i] = read() + off;
  return v;
}
template <class T>
void print(const vector<T>& v, int suc = 1) {
  for (int i = int(0); i < int(v.size()); i++)
    print(v[i], i == int(v.size()) - 1 ? suc : 2);
}
string readString() {
  string s;
  cin >> s;
  return s;
}
template <class T>
T sq(const T& t) {
  return t * t;
}
void yes(bool ex = true) {
  cout << "Yes"
       << "\n";
  if (ex) exit(0);
}
void no(bool ex = true) {
  cout << "No"
       << "\n";
  if (ex) exit(0);
}
void possible(bool ex = true) {
  cout << "Possible"
       << "\n";
  if (ex) exit(0);
}
void impossible(bool ex = true) {
  cout << "Impossible"
       << "\n";
  if (ex) exit(0);
}
constexpr ll ten(int n) { return n == 0 ? 1 : ten(n - 1) * 10; }
const ll infLL = LLONG_MAX / 3;
const int inf = INT_MAX / 2 - 100;
int topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }
int topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }
int botbit(signed first) { return first == 0 ? 32 : __builtin_ctz(first); }
int botbit(ll first) { return first == 0 ? 64 : __builtin_ctzll(first); }
int popcount(signed t) { return __builtin_popcount(t); }
int popcount(ll t) { return __builtin_popcountll(t); }
bool ispow2(int i) { return i && (i & -i) == i; }
ll mask(int i) { return (ll(1) << i) - 1; }
bool inc(int first, int second, int c) {
  return first <= second && second <= c;
}
template <class t>
void mkuni(vc<t>& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
ll rand_int(ll l, ll r) {
  static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
  return uniform_int_distribution<ll>(l, r)(gen);
}
template <class t>
void myshuffle(vc<t>& first) {
  for (int i = int(0); i < int(int(first.size())); i++)
    swap(first[i], first[rand_int(0, i)]);
}
template <class t>
int lwb(const vc<t>& v, const t& first) {
  return lower_bound(v.begin(), v.end(), first) - v.begin();
}
struct unionfind {
  vi p, s;
  int c;
  unionfind(int n) : p(n, -1), s(n, 1), c(n) {}
  int find(int first) {
    return p[first] == -1 ? first : (p[first] = find(p[first]));
  }
  bool unite(int first, int second) {
    first = find(first);
    second = find(second);
    if (first == second) return false;
    p[second] = first;
    s[first] += s[second];
    c--;
    return true;
  }
  bool same(int first, int second) { return find(first) == find(second); }
  int sz(int first) { return s[find(first)]; }
};
void imp() {
  print(-1);
  exit(0);
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
  int n, k;
  cin >> n >> k;
  vvc<int> d(n, vi(k));
  for (int i = int(0); i < int(k); i++) {
    for (int j = int(0); j < int(n); j++) {
      cin >> d[j][i];
    }
  }
  vi rs(k, -1);
  for (int i = int(0); i < int(n); i++)
    for (int j = int(0); j < int(k); j++)
      if (d[i][j] == 0) rs[j] = i;
  for (int i = int(0); i < int(k); i++)
    if (rs[i] == -1) imp();
  if (int(rs.size()) != k) imp();
  vi idx(n);
  iota(idx.begin(), idx.end(), 0);
  sort(idx.begin(), idx.end(), [&](int i, int j) { return d[i] < d[j]; });
  unionfind uf(n);
  vvc<int> t(n);
  vc<pi> es;
  auto ae = [&](int first, int second) {
    if (first == -1 || second == -1) {
      imp();
    }
    if (uf.same(first, second)) return;
    void(0);
    uf.unite(first, second);
    es.emplace_back(first, second);
    t[first].push_back(second);
    t[second].push_back(first);
  };
  vc<bool> in(n, 1);
  for (int i = int(0); i < int(n); i++) {
    vi c = d[i];
    for (int j = int(0); j < int(k); j++) c[j]--;
    int to = *lower_bound(idx.begin(), idx.end(), c,
                          [&](int x, const vi& y) { return d[x] < y; });
    if (d[to] == c) {
      ae(to, i);
      in[i] = 0;
    }
  }
  void(0);
  for (int v = int(1); v < int(k); v++) {
    int len = d[rs[0]][v];
    vi ls(len + 1, -1);
    for (int i = int(0); i < int(n); i++)
      if (in[i] && d[i][0] + d[i][v] == len) ls[d[i][0]] = i;
    void(0);
    for (int i = int(0); i < int(len); i++) ae(ls[i], ls[i + 1]);
  }
  void(0);
  if (uf.c != 1) imp();
  void(0);
  for (int r = int(0); r < int(k); r++) {
    vi dist(n, -1);
    queue<int> q;
    auto reach = [&](int v, int d) {
      if (dist[v] != -1) return;
      dist[v] = d;
      q.push(v);
    };
    reach(rs[r], 0);
    while (int(q.size())) {
      int v = q.front();
      q.pop();
      for (auto to : t[v]) reach(to, dist[v] + 1);
    }
    void(0);
    for (int i = int(0); i < int(n); i++)
      if (d[i][r] != dist[i]) {
        imp();
      }
  }
  for (auto e : es) {
    print(e.first + 1, 2);
    print(e.second + 1);
  }
}