#include <bits/stdc++.h>
typedef struct {
  int data, i, j;
} node;
int ufs[1000005];
node table[1000005];
int mxrow[1000005], mxcol[1000005];
int markc[1000005];
int n, m, mn;
int nwtbl[1000005];
int resbl[1000005];
void input_data(void) {
  scanf("%d %d", &n, &m);
  mn = n * m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int k = i * m + j;
      table[k].i = i, table[k].j = j;
      scanf("%d", table + k);
    }
  }
}
int cmp(const void *p1, const void *p2) {
  node *a = (node *)p1, *b = (node *)p2;
  if (a->data > b->data) return 1;
  if (a->data < b->data) return -1;
  if (a->i > b->i) return 1;
  if (a->i < b->i) return -1;
  if (a->j > b->j) return 1;
  return -1;
}
void ufs_init(void) {
  for (int i = 0; i < mn; i++) ufs[i] = i;
}
int find_boss(int k) {
  if (ufs[k] != k) ufs[k] = find_boss(ufs[k]);
  return ufs[k];
}
void ufs_union(int boss, int slave) { ufs[find_boss(slave)] = find_boss(boss); }
void ufs_joint(int l, int r) {
  markc[table[l].j] = l;
  for (int i = l + 1; i < r; i++) {
    if (table[i].i == table[i - 1].i) ufs_union(i - 1, i);
    if (markc[table[i].j] != -1) ufs_union(markc[table[i].j], i);
    markc[table[i].j] = i;
  }
  while (l < r) markc[table[l++].j] = -1;
}
void get_key(int l, int r) {
  for (int i = l; i < r; i++) {
    int fi = find_boss(i);
    nwtbl[fi] =
        (nwtbl[fi] > mxrow[table[i].i] + 1 ? nwtbl[fi] : mxrow[table[i].i] + 1);
    nwtbl[fi] =
        (nwtbl[fi] > mxcol[table[i].j] + 1 ? nwtbl[fi] : mxcol[table[i].j] + 1);
  }
  for (int i = l; i < r; i++) {
    resbl[table[i].i * m + table[i].j] = mxrow[table[i].i] = mxcol[table[i].j] =
        nwtbl[ufs[i]];
  }
}
void get_new(void) {
  int l = 0, r = 0;
  ufs_init();
  memset(markc, -1, sizeof(markc[0]) * m);
  while (r < mn) {
    for (l = r++; table[r].data == table[l].data && r < mn; r++)
      ;
    ufs_joint(l, r);
    get_key(l, r);
  }
}
int get_res() {
  int res = -1;
  for (int i = 0; i < mn; i++) {
    printf("%d ", resbl[i]);
    if ((i + 1) % m == 0) printf("\n");
  }
  return res;
}
int main() {
  input_data();
  qsort(table, n * m, sizeof(table[0]), cmp);
  get_new();
  int res = get_res();
  return 0;
}
