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;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1e18;
int N, K;
vector<int> vertex;
vector<int> d[200];
set<pair<int, int>> st;
vector<int> g[30000];
int dist[200][30000];
void dfs(int idx, int now, int from) {
  for (auto to : g[now]) {
    if (to == from) continue;
    dist[idx][to] = dist[idx][now] + 1;
    dfs(idx, to, now);
  }
}
set<int> appear;
map<int, vector<pair<int, int>>> children;
struct UnionFind {
  vector<int> par;
  vector<int> rank;
  vector<long long> Size;
  UnionFind(int n = 1) { init(n); }
  void init(int n = 1) {
    par.resize(n + 1);
    rank.resize(n + 1);
    Size.resize(n + 1);
    for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
  }
  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      int r = root(par[x]);
      return par[x] = r;
    }
  }
  bool issame(int x, int y) { return root(x) == root(y); }
  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (rank[x] < rank[y]) swap(x, y);
    if (rank[x] == rank[y]) ++rank[x];
    par[y] = x;
    Size[x] += Size[y];
    return true;
  }
  long long size(int x) { return Size[root(x)]; }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> K;
  vertex.resize(K, -1);
  for (int k = 0; k < K; k++) {
    d[k].resize(N);
    for (int i = 0; i < N; i++) {
      cin >> d[k][i];
      if (d[k][i] == 0) {
        if (vertex[k] != -1) {
          cout << -1 << endl;
          return 0;
        } else {
          vertex[k] = i;
        }
      }
    }
    if (vertex[k] == -1) {
      cout << -1 << endl;
      return 0;
      ;
    }
    appear.insert(vertex[k]);
  }
  for (int k = 1; k < K; k++) {
    int mini = d[0][vertex[k]];
    vector<int> v(mini + 1, -1);
    for (int i = 0; i < N; i++) {
      if (d[0][i] + d[k][i] < mini) {
        cout << -1 << endl;
      }
      if (d[0][i] + d[k][i] == mini) {
        if (v[d[0][i]] != -1) {
          cout << -1 << endl;
          return 0;
          ;
        }
        v[d[0][i]] = i;
      }
    }
    for (int i = 0; i <= mini; i++) {
      if (v[i] == -1) {
        cout << -1 << endl;
        return 0;
        ;
      }
    }
    for (int i = 0; i < mini; i++) {
      int a = v[i];
      int b = v[i + 1];
      if (a > b) swap(a, b);
      st.insert({a, b});
    }
  }
  UnionFind uni(N);
  for (auto tmp : st) {
    if (!uni.merge(tmp.first, tmp.second)) {
      cout << -1 << endl;
      return 0;
    } else {
      g[tmp.first].push_back(tmp.second);
      g[tmp.second].push_back(tmp.first);
      appear.insert(tmp.first);
      appear.insert(tmp.second);
    }
  }
  map<vector<int>, int> mp;
  for (int i = 0; i < N; i++) {
    if (appear.find(i) == appear.end()) continue;
    vector<int> v(K);
    int mini = 1e9;
    for (int j = 0; j < K; j++) {
      v[j] = d[j][i];
      chmin(mini, v[j]);
    }
    for (int j = 0; j < K; j++) {
      v[j] -= mini;
    }
    mp[v] = i;
  }
  for (int i = 0; i < N; i++) {
    if (appear.find(i) != appear.end()) continue;
    vector<int> v(K);
    int mini = 1e9;
    for (int j = 0; j < K; j++) {
      v[j] = d[j][i];
      chmin(mini, v[j]);
    }
    for (int j = 0; j < K; j++) {
      v[j] -= mini;
    }
    if (mp.count(v)) {
      int p = mp[v];
      int len = d[0][i] - d[0][p];
      if (len <= 0) {
        cout << -1 << endl;
        return 0;
      }
      children[p].push_back({len, i});
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    if (children[i].empty()) continue;
    auto v = children[i];
    sort(v.begin(), v.end());
    if (v[0].first != 1) {
      cout << -1 << endl;
      return 0;
    }
    int Last = i;
    st.insert({i, v[0].second});
    g[Last].push_back(v[0].second);
    g[v[0].second].push_back(Last);
    for (int i = 1; i < v.size(); i++) {
      if (v[i].first > v[i - 1].first + 1) {
        cout << -1 << endl;
        return 0;
      } else if (v[i].first == v[i - 1].first) {
        st.insert({Last, v[i].second});
        g[Last].push_back(v[i].second);
        g[v[i].second].push_back(Last);
      } else {
        Last = v[i - 1].second;
        st.insert({Last, v[i].second});
        g[Last].push_back(v[i].second);
        g[v[i].second].push_back(Last);
      }
    }
  }
  for (int i = 0; i < K; i++) {
    dfs(i, vertex[i], -1);
    for (int j = 0; j < N; j++) {
      if (dist[i][j] != d[i][j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (auto e : st) {
    cout << e.first + 1 << " " << e.second + 1 << endl;
  }
  return 0;
}