#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
queue<int> q;
int n, m, cnt, ans, r[maxn], da[maxn], fa[maxn], deg[maxn], dep[maxn];
vector<int> mat[maxn], idx[maxn], G[maxn];
int cmp(int a, int b) { return da[a] == da[b] ? a < b : da[a] < da[b]; }
int getv(int id) {
  int x = (id - 1) / m + 1;
  int y = id % m;
  return mat[x][y == 0 ? m : y];
}
void adde(int a, int b) {
  if (getv(a) == getv(b)) return;
  G[a].push_back(b);
  ++deg[b];
}
int find(int a) { return fa[a] == a ? a : fa[a] = find(fa[a]); }
void merge(int a, int b) { fa[find(a)] = find(b); }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    mat[i].push_back(0);
    idx[i].push_back(0);
    for (int j = 1, x; j <= m; ++j) {
      scanf("%d", &x);
      mat[i].push_back(x);
      idx[i].push_back(++cnt);
      fa[cnt] = cnt;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) r[j] = j, da[j] = mat[i][j];
    sort(r + 1, r + m + 1, cmp);
    for (int j = 1, k; j <= m;) {
      k = j + 1;
      while (k <= m && da[r[j]] == da[r[k]]) {
        merge(idx[i][r[j]], idx[i][r[k]]);
        ++k;
      }
      j = k;
    }
  }
  for (int j = 1; j <= m; ++j) {
    for (int i = 1; i <= n; ++i) r[i] = i, da[i] = mat[i][j];
    sort(r + 1, r + n + 1, cmp);
    for (int i = 1, k; i <= n;) {
      k = i + 1;
      while (k <= n && da[r[i]] == da[r[k]]) {
        merge(idx[r[i]][j], idx[r[k]][j]);
        ++k;
      }
      i = k;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) r[j] = j, da[j] = mat[i][j];
    sort(r + 1, r + m + 1, cmp);
    for (int j = 1; j < m; ++j)
      adde(find(idx[i][r[j]]), find(idx[i][r[j + 1]]));
  }
  for (int j = 1; j <= m; ++j) {
    for (int i = 1; i <= n; ++i) r[i] = i, da[i] = mat[i][j];
    sort(r + 1, r + n + 1, cmp);
    for (int i = 1; i < n; ++i)
      adde(find(idx[r[i]][j]), find(idx[r[i + 1]][j]));
  }
  for (int i = 1; i <= cnt; ++i)
    if (!deg[i] && i == find(i)) {
      dep[i] = 1;
      q.push(i);
    }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    ans = max(ans, dep[u]);
    for (int i = 0, v; i < (int)G[u].size(); ++i) {
      v = G[u][i];
      dep[v] = max(dep[v], dep[u] + 1);
      if (--deg[v] == 0) {
        q.push(v);
      }
    }
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      printf("%d%c", dep[find(idx[i][j])], " \n"[j == m]);
  return 0;
}
