#include <bits/stdc++.h>
int e_n;
struct edge {
  int to;
  int next;
} e[3000000];
struct P {
  int b;
  int v;
} d[1001000];
void Max(int &num1, int num2) {
  if (num1 < num2) num1 = num2;
}
int n, m;
int i, j, k;
int fa, fb;
int w[1001000];
int in[1001000];
int far[1001000];
int top, tai;
int sta[4000000];
int tab[1001000];
int ans[1001000];
int getf(int d) { return far[d] == d ? d : far[d] = getf(far[d]); }
bool cmpv(const P &X, const P &Y) { return X.v < Y.v; }
void addedge(int from, int to) {
  e[e_n].to = to;
  e[e_n].next = w[from];
  w[from] = e_n++;
}
void work() {
  top = tai = 0;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      if (in[far[(i - 1) * m + j]] == 0)
        if (ans[far[(i - 1) * m + j]] == 0) {
          sta[++tai] = far[(i - 1) * m + j];
          ans[far[(i - 1) * m + j]] = 1;
        }
  for (top = 0; ++top <= tai;)
    for (i = w[sta[top]]; i >= 0; i = e[i].next) {
      Max(ans[e[i].to], ans[sta[top]] + 1);
      if (!--in[e[i].to]) sta[++tai] = e[i].to;
    }
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n * m; i++) far[i] = i;
  for (i = 1; i <= n * m; i++) w[i] = -1;
  for (i = 1; i <= n * m; i++) scanf("%d", &tab[i]);
  for (i = 1; i <= n; i++) {
    for (j = 0; ++j <= m; d[j].b = (i - 1) * m + j)
      d[j].v = tab[(i - 1) * m + j];
    std::sort(d + 1, d + 1 + m, cmpv);
    for (j = 0; ++j < m;)
      if (d[j].v == d[j + 1].v) {
        fa = getf(d[j].b);
        fb = getf(d[j + 1].b);
        far[fa] = fb;
      }
  }
  for (j = 1; j <= m; j++) {
    for (i = 0; ++i <= n; d[i].b = (i - 1) * m + j)
      d[i].v = tab[(i - 1) * m + j];
    std::sort(d + 1, d + 1 + n, cmpv);
    for (i = 0; ++i < n;)
      if (d[i].v == d[i + 1].v) {
        fa = getf(d[i].b);
        fb = getf(d[i + 1].b);
        far[fa] = fb;
      }
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; ++j <= m; d[j].b = ((i - 1) * m) + j)
      d[j].v = tab[(i - 1) * m + j];
    std::sort(d + 1, d + 1 + m, cmpv);
    for (j = m; j > 1; j--)
      if (d[j].v != d[j - 1].v) {
        fa = getf(d[j].b);
        fb = getf(d[j - 1].b);
        addedge(fb, fa);
        in[fa]++;
      }
  }
  for (j = 1; j <= m; j++) {
    for (i = 0; ++i <= n; d[i].b = ((i - 1) * m + j))
      d[i].v = tab[(i - 1) * m + j];
    std::sort(d + 1, d + 1 + n, cmpv);
    for (i = n; i > 1; i--)
      if (d[i].v != d[i - 1].v) {
        fa = getf(d[i].b);
        fb = getf(d[i - 1].b);
        addedge(fb, fa);
        in[fa]++;
      }
  }
  work();
  for (i = 0; ++i <= n; printf("\n"))
    for (j = 0; ++j <= m; printf("%d ", ans[getf((i - 1) * m + j)]))
      ;
}
