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;
int n, m, father[1000010];
vector<int> a[1000010], num[1000010];
vector<pair<int, int> > wz[1000010];
map<int, int> mp;
map<int, int> ans, mxx, mxy;
priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int> >,
               greater<pair<pair<int, int>, int> > >
    pq;
int xy(int x, int y) { return (x - 1) * m + y; }
int findfather(int x) {
  if (father[x] == x)
    return father[x];
  else
    return father[x] = findfather(father[x]);
}
void ak(int aa, int bb) {
  int a1 = findfather(aa), b1 = findfather(bb);
  if (a1 != b1) father[a1] = b1;
}
int main() {
  int MX, len, i, j, val, x, y, cc, s1;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) {
    a[i].push_back(0);
    num[i].push_back(0);
    for (j = 1; j <= m; j++) {
      scanf("%d", &s1);
      a[i].push_back(s1);
      num[i].push_back(xy(i, j));
      pq.push(make_pair(make_pair(a[i][j], i), j));
    }
  }
  for (i = 1; i <= n * m; i++) father[i] = i;
  for (i = 1; i <= n; i++) {
    mp.clear();
    for (j = 1; j <= m; j++) {
      if (mp[a[i][j]] == 0)
        mp[a[i][j]] = findfather(num[i][j]);
      else
        ak(mp[a[i][j]], num[i][j]);
    }
  }
  for (j = 1; j <= m; j++) {
    mp.clear();
    for (i = 1; i <= n; i++) {
      if (mp[a[i][j]] == 0)
        mp[a[i][j]] = findfather(num[i][j]);
      else
        ak(mp[a[i][j]], num[i][j]);
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++)
      wz[findfather(num[i][j])].push_back(make_pair(i, j));
  }
  while (!pq.empty()) {
    pair<pair<int, int>, int> T = pq.top();
    pq.pop();
    val = T.first.first;
    x = T.first.second;
    y = T.second;
    if (ans[findfather(num[x][y])] == 0) {
      MX = 0;
      len = wz[findfather(num[x][y])].size();
      for (i = 0; i < len; i++) {
        MX = max(MX, max(mxx[wz[findfather(num[x][y])][i].first],
                         mxy[wz[findfather(num[x][y])][i].second]));
      }
      ans[findfather(num[x][y])] = MX + 1;
      cc = ans[findfather(num[x][y])];
      mxx[x] = max(mxx[x], cc);
      mxy[y] = max(mxy[y], cc);
    } else {
      cc = ans[findfather(num[x][y])];
      mxx[x] = max(mxx[x], cc);
      mxy[y] = max(mxy[y], cc);
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) printf("%d ", ans[findfather(num[i][j])]);
    printf("\n");
  }
  return 0;
}
