#include <bits/stdc++.h>
using namespace std;
struct UF {
  vector<int> x;
  UF(int n) : x(n, -1) {}
  int find(int i) { return x[i] < 0 ? i : x[i] = find(x[i]); }
  bool merge(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b) return false;
    x[b] = a;
    return true;
  }
};
void put(set<pair<int, int>>& adj, int a, int b) {
  if (a != b) adj.emplace(min(a, b), max(a, b));
}
namespace std {
template <>
struct hash<vector<int>> {
  size_t operator()(const vector<int>& k) const {
    size_t ret = 0;
    for (int x : k) ret = (ret * 7) ^ hash<int>()(x);
    return ret;
  }
};
};  // namespace std
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<vector<int>> dist(k, vector<int>(n));
  vector<int> ids(k);
  unordered_map<vector<int>, int> order;
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n; j++) {
      cin >> dist[i][j];
      if (dist[i][j] == 0) ids[i] = j;
    }
  }
  vector<int> turn(k);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) turn[j] = dist[j][i];
    order[turn] = i;
  }
  set<pair<int, int>> adj;
  for (int i = 1; i < k; i++) {
    vector<pair<int, int>> path;
    int inside = dist[0][ids[i]];
    for (int j = 0; j < n; j++) {
      int len = dist[0][j] + dist[i][j];
      if (len == inside) path.emplace_back(dist[0][j], j);
    }
    sort(path.begin(), path.end());
    for (int j = 1; j < path.size(); j++)
      put(adj, path[j - 1].second, path[j].second);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) turn[j] = dist[j][i] - 1;
    auto x = order.find(turn);
    if (x != order.end()) put(adj, i, x->second);
  }
  bool ok = true;
  if (adj.size() != n - 1) ok = false;
  UF uf(n);
  for (auto& e : adj)
    if (!uf.merge(e.first, e.second)) ok = false;
  if (ok)
    for (auto& e : adj) cout << (e.first + 1) << " " << (e.second + 1) << "\n";
  else
    cout << "-1\n";
  return 0;
}

### Prompt

Construct a CPP code solution to the problem outlined:

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>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct UF {
  vector<int> x;
  UF(int n) : x(n, -1) {}
  int find(int i) { return x[i] < 0 ? i : x[i] = find(x[i]); }
  bool merge(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b) return false;
    x[b] = a;
    return true;
  }
};
void put(set<pair<int, int>>& adj, int a, int b) {
  if (a != b) adj.emplace(min(a, b), max(a, b));
}
namespace std {
template <>
struct hash<vector<int>> {
  size_t operator()(const vector<int>& k) const {
    size_t ret = 0;
    for (int x : k) ret = (ret * 7) ^ hash<int>()(x);
    return ret;
  }
};
};  // namespace std
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<vector<int>> dist(k, vector<int>(n));
  vector<int> ids(k);
  unordered_map<vector<int>, int> order;
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n; j++) {
      cin >> dist[i][j];
      if (dist[i][j] == 0) ids[i] = j;
    }
  }
  vector<int> turn(k);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) turn[j] = dist[j][i];
    order[turn] = i;
  }
  set<pair<int, int>> adj;
  for (int i = 1; i < k; i++) {
    vector<pair<int, int>> path;
    int inside = dist[0][ids[i]];
    for (int j = 0; j < n; j++) {
      int len = dist[0][j] + dist[i][j];
      if (len == inside) path.emplace_back(dist[0][j], j);
    }
    sort(path.begin(), path.end());
    for (int j = 1; j < path.size(); j++)
      put(adj, path[j - 1].second, path[j].second);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) turn[j] = dist[j][i] - 1;
    auto x = order.find(turn);
    if (x != order.end()) put(adj, i, x->second);
  }
  bool ok = true;
  if (adj.size() != n - 1) ok = false;
  UF uf(n);
  for (auto& e : adj)
    if (!uf.merge(e.first, e.second)) ok = false;
  if (ok)
    for (auto& e : adj) cout << (e.first + 1) << " " << (e.second + 1) << "\n";
  else
    cout << "-1\n";
  return 0;
}

```