#include <bits/stdc++.h>
using namespace std;
vector<int> E[1000005];
struct way {
  int num, next;
} G[6 * 1000005];
int d[1000005], head[1000005];
int n, m, len, f[1000005], a[1000005], b[1000005], dfn[1000005], low[1000005],
    st[1000005], scc[1000005], dfs_clock, scc_cnt, top;
int gd(int x, int y) { return (x - 1) * m + y; }
bool cmp(int x, int y) { return a[x] < a[y]; }
void link(int x, int y) { G[++len] = (way){y, head[x]}, head[x] = len; }
void Tarjan(int t) {
  int i;
  st[++top] = t;
  dfn[t] = low[t] = ++dfs_clock;
  for (i = 0; i < E[t].size(); i++)
    if (!dfn[E[t][i]])
      Tarjan(E[t][i]), low[t] = min(low[t], low[E[t][i]]);
    else if (!scc[E[t][i]])
      low[t] = min(low[t], dfn[E[t][i]]);
  if (dfn[t] == low[t]) {
    ++scc_cnt;
    while (1) {
      scc[st[top]] = scc_cnt;
      if (st[top--] == t) break;
    }
  }
}
void topsort() {
  int i, x, cnt = 0;
  queue<int> Q;
  for (i = 1; i <= scc_cnt; i++)
    if (!d[i]) Q.push(i);
  memset(dfn, 0, sizeof(dfn));
  while (!Q.empty()) {
    x = Q.front(), Q.pop(), dfn[++cnt] = x;
    for (i = head[x]; i; i = G[i].next)
      if (!(--d[G[i].num])) Q.push(G[i].num);
  }
}
void update(int x) {
  int i;
  f[x] = 1;
  for (i = head[x]; i; i = G[i].next) f[x] = max(f[x], f[G[i].num] + 1);
}
int main() {
  int i, j, k;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) scanf("%d", &a[gd(i, j)]);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) b[j] = gd(i, j);
    sort(b + 1, b + m + 1, cmp);
    for (j = 1; j <= m; j = k)
      for (k = j; k <= m && a[b[k]] == a[b[j]]; k++) {
        if (k > 1) E[b[k]].push_back(b[k - 1]);
        if (a[b[k + 1]] == a[b[k]]) E[b[k]].push_back(b[k + 1]);
      }
  }
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++) b[j] = gd(j, i);
    sort(b + 1, b + n + 1, cmp);
    for (j = 1; j <= n; j = k)
      for (k = j; k <= n && a[b[k]] == a[b[j]]; k++) {
        if (k > 1) E[b[k]].push_back(b[k - 1]);
        if (a[b[k + 1]] == a[b[k]]) E[b[k]].push_back(b[k + 1]);
      }
  }
  for (i = 1; i <= n * m; i++)
    if (!dfn[i]) Tarjan(i);
  for (i = 1; i <= n * m; i++)
    for (j = 0; j < E[i].size(); j++)
      if (scc[i] != scc[E[i][j]]) link(scc[i], scc[E[i][j]]);
  for (i = 1; i <= scc_cnt; i++)
    for (j = head[i]; j; j = G[j].next) d[G[j].num]++;
  topsort();
  for (i = scc_cnt; i >= 1; i--) update(dfn[i]);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) printf("%d ", f[scc[gd(i, j)]]);
    printf("\n");
  }
  return 0;
}
