Little Petya is now fond of data compression algorithms. He has already studied gz, bz, zip algorithms and many others. Inspired by the new knowledge, Petya is now developing the new compression algorithm which he wants to name dis.

Petya decided to compress tables. He is given a table a consisting of n rows and m columns that is filled with positive integers. He wants to build the table a' consisting of positive integers such that the relative order of the elements in each row and each column remains the same. That is, if in some row i of the initial table ai, j < ai, k, then in the resulting table a'i, j < a'i, k, and if ai, j = ai, k then a'i, j = a'i, k. Similarly, if in some column j of the initial table ai, j < ap, j then in compressed table a'i, j < a'p, j and if ai, j = ap, j then a'i, j = a'p, j. 

Because large values require more space to store them, the maximum value in a' should be as small as possible.

Petya is good in theory, however, he needs your help to implement the algorithm.

Input

The first line of the input contains two integers n and m (<image>, the number of rows and the number of columns of the table respectively.

Each of the following n rows contain m integers ai, j (1 ≤ ai, j ≤ 109) that are the values in the table.

Output

Output the compressed table in form of n lines each containing m integers.

If there exist several answers such that the maximum number in the compressed table is minimum possible, you are allowed to output any of them.

Examples

Input

2 2
1 2
3 4


Output

1 2
2 3


Input

4 3
20 10 30
50 40 30
50 60 70
90 80 70


Output

2 1 3
5 4 3
5 6 7
9 8 7

Note

In the first sample test, despite the fact a1, 2 ≠ a21, they are not located in the same row or column so they may become equal after the compression.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
pair<int, pair<int, int> > A[maxn];
map<int, int> X;
map<int, int> Y;
int Hx[maxn], Hy[maxn];
int ans[maxn];
int fa[maxn];
int fi(int u) { return u != fa[u] ? fa[u] = fi(fa[u]) : u; }
void uni(int u, int v) {
  int p1 = fi(u), p2 = fi(v);
  if (p1 != p2) fa[p1] = p2;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n * m; i++) {
    fa[i] = i;
    scanf("%d", &A[i].first);
    A[i].second.first = i / m;
    A[i].second.second = i % m;
  }
  int j = -1;
  sort(A, A + n * m);
  for (int i = 0; i < n * m; i++) {
    if (i != n * m - 1 && A[i].first == A[i + 1].first) continue;
    for (int k = j + 1; k <= i; k++) {
      int p = A[k].second.first * m + A[k].second.second;
      int x = A[k].second.first, y = A[k].second.second;
      Hx[x] = p;
      Hy[y] = p;
    }
    for (int k = j + 1; k <= i; k++) {
      int p = A[k].second.first * m + A[k].second.second;
      int x = A[k].second.first, y = A[k].second.second;
      uni(Hx[x], p);
      uni(Hy[y], p);
    }
    for (int k = j + 1; k <= i; k++) {
      int p = A[k].second.first * m + A[k].second.second;
      int x = A[k].second.first, y = A[k].second.second;
      int pa = fi(p);
      ans[pa] = max(ans[pa], max(X[x], Y[y]) + 1);
    }
    for (int k = j + 1; k <= i; k++) {
      int p = A[k].second.first * m + A[k].second.second;
      int x = A[k].second.first, y = A[k].second.second;
      X[x] = max(X[x], ans[fi(p)]);
      Y[y] = max(Y[y], ans[fi(p)]);
    }
    j = i;
  }
  for (int i = 0; i < n * m; i++) {
    printf("%d ", ans[fi(i)]);
    if (i % m == m - 1) printf("\n");
  }
  return 0;
}
