#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, T, tot;
const int N = 1000100;
struct data {
  int r, c, v, id;
} p[N];
bool cmp(const data &a, const data &b) { return a.v < b.v; }
int f[N], X[N], Y[N], ans[N], x[N], y[N], tmp[N];
int Find(int a) { return a == f[a] ? f[a] : f[a] = Find(f[a]); }
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      scanf("%d", &p[++tot].v);
      p[tot].r = i, p[tot].c = j;
      p[tot].id = tot;
      f[tot] = tot;
    }
  sort(p + 1, p + 1 + tot, cmp);
  for (i = 1; i <= tot; i = j) {
    for (j = i; p[i].v == p[j].v; ++j)
      ;
    for (k = i; k < j; k++) {
      int r = p[k].r, c = p[k].c;
      if (!x[r])
        x[r] = k;
      else
        f[Find(k)] = Find(x[r]);
      if (!y[c])
        y[c] = k;
      else
        f[Find(k)] = Find(y[c]);
    }
    for (k = i; k < j; k++) {
      int q = Find(k);
      tmp[q] = max(tmp[q], max(X[p[k].r], Y[p[k].c]) + 1);
    }
    for (k = i; k < j; k++) {
      x[p[k].r] = y[p[k].c] = 0;
      X[p[k].r] = Y[p[k].c] = ans[p[k].id] = tmp[Find(k)];
    }
  }
  for (i = 1; i <= tot; i++) {
    printf("%d ", ans[i]);
    if (i % m == 0) puts("");
  }
}
