#include <bits/stdc++.h>
using namespace std;
typedef struct {
  int v, x, y;
} cell;
bool cmp(cell a, cell b) { return a.v < b.v; }
bool cmp2(cell a, cell b) {
  if (a.x == b.x)
    return a.y < b.y;
  else
    return a.x < b.x;
}
cell a[1000000];
int p[2000000];
int dep[2000000];
int mx[2][2000000];
int root(int v) {
  if (p[v] == v)
    return v;
  else {
    int r = root(p[v]);
    p[v] = r;
    return r;
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int v;
      scanf("%d", &v);
      a[m * i + j].x = i;
      a[m * i + j].y = j;
      a[m * i + j].v = v;
    }
  int N = n * m;
  sort(a, a + N, cmp);
  int l = 0, r;
  while (l < N) {
    for (r = l; r + 1 < N && a[r + 1].v == a[l].v; r++)
      ;
    for (int i = l; i <= r; i++) {
      p[a[i].x] = a[i].x;
      p[a[i].y + n] = a[i].y + n;
      dep[a[i].x] = 0;
      dep[a[i].y + n] = 0;
      mx[1][a[i].x] = 0;
      mx[1][a[i].y + n] = 0;
    }
    for (int i = l; i <= r; i++) {
      int r1 = root(a[i].x);
      int r2 = root(a[i].y + n);
      if (dep[r1] >= dep[r2])
        p[r2] = r1;
      else
        p[r1] = r2;
      if (dep[r1] == dep[r2]) dep[r1]++;
    }
    for (int i = l; i <= r; i++) {
      int r1 = root(a[i].x);
      if (mx[1][r1] < mx[0][a[i].x] + 1) mx[1][r1] = mx[0][a[i].x] + 1;
      if (mx[1][r1] < mx[0][a[i].y + n] + 1) mx[1][r1] = mx[0][a[i].y + n] + 1;
    }
    for (int i = l; i <= r; i++) {
      int r1 = root(a[i].x);
      mx[0][a[i].x] = mx[1][r1];
      mx[0][a[i].y + n] = mx[1][r1];
      a[i].v = mx[1][r1];
    }
    l = r + 1;
  }
  sort(a, a + N, cmp2);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) printf("%d ", a[i * m + j].v);
    printf("\n");
  }
  return 0;
}
