#include <bits/stdc++.h>
unsigned A[1111111], N[1111111], Rv[1111111], Cv[1111111], V[1111111],
    D[1111111], J[1111111];
unsigned *R[1111111], *C[1111111], Ri[1111111], Ci[1111111], Ra[1111111],
    Ca[1111111];
unsigned Vr[1111111], Vc[1111111];
void add(unsigned **X, unsigned *Xi, unsigned *Xa, unsigned i, unsigned j) {
  if (Xi[i] == Xa[i]) {
    if (!Xa[i])
      X[i] = (unsigned *)calloc(Xa[i] = 2, sizeof(unsigned));
    else
      X[i] = (unsigned *)realloc(X[i], (Xa[i] <<= 1) * sizeof(unsigned));
  }
  X[i][Xi[i]++] = j;
  return;
}
int F(const void *x, const void *y) {
  if (A[*(unsigned *)x] > A[*(unsigned *)y]) return 1;
  if (A[*(unsigned *)x] < A[*(unsigned *)y]) return -1;
  return 0;
}
unsigned t, x, y;
void G(unsigned n) {
  if (V[n] == t) return;
  V[n] = t;
  unsigned i, r = n / y, c = n % y;
  if (D[t] < Rv[r]) D[t] = Rv[r];
  if (D[t] < Cv[c]) D[t] = Cv[c];
  if (Vr[r] != t)
    for (Vr[r] = t, i = Ri[r]; i--;) G(R[r][i]);
  if (Vc[c] != t)
    for (Vc[c] = t, i = Ci[c]; i--;) G(C[c][i]);
  return;
}
int main() {
  unsigned i, j, k, l, r, c, w;
  scanf("%u%u", &x, &y);
  l = x * y;
  for (i = -1; ++i < l; N[i] = i) scanf("%u", A + i);
  qsort(N, l, sizeof(unsigned), F);
  A[N[l] = l] = -1;
  for (i = j = 0; ++j <= l;)
    if (A[N[j]] != A[N[i]]) {
      for (w = i - 1; ++w < j;) {
        k = N[w];
        r = k / y;
        c = k % y;
        add(R, Ri, Ra, r, k);
        add(C, Ci, Ca, c, k);
      }
      for (w = i - 1; ++w < j;) {
        k = N[w];
        r = k / y;
        c = k % y;
        if (!V[k]) {
          ++t;
          G(k);
        }
        Rv[r] = Cv[c] = J[k] = D[V[k]] + 1;
      }
      for (w = i - 1; ++w < j;) {
        k = N[w];
        r = k / y;
        c = k % y;
        Ri[r] = Ci[c] = 0;
      }
      i = j;
    }
  for (i = -1, j = 0; ++i < l;) {
    printf("%u", J[i]);
    if (++j == y) {
      putchar('\n');
      j = 0;
    } else
      putchar(' ');
  }
  return 0;
}
