#include <bits/stdc++.h>
using namespace std;
struct rec2 {
  int num, next;
};
struct rec1 {
  int x, y, biao, num;
};
rec1 matrix[1001000];
rec2 e[2001000];
int fa[1001000], q[1000100], f[1001000], e_tot, link[1001000], n, m,
    ru[1000100];
bool flag[1000100];
int getfather(int x) {
  if (fa[x] == x) return x;
  return fa[x] = getfather(fa[x]);
}
int merge(int x, int y) {
  int gen1 = getfather(x);
  int gen2 = getfather(y);
  if (gen1 != gen2) fa[gen2] = gen1;
}
void insert(int a, int b) {
  e_tot++;
  e[e_tot].num = b;
  e[e_tot].next = link[a];
  link[a] = e_tot;
}
int cmp1(rec1 a, rec1 b) {
  if (a.x != b.x) return a.x < b.x;
  return a.num < b.num;
}
int cmp2(rec1 a, rec1 b) {
  if (a.y != b.y) return a.y < b.y;
  return a.num < b.num;
}
int cmp3(rec1 a, rec1 b) { return a.biao < b.biao; }
void input() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%d", &matrix[(i - 1) * m + j].num);
      matrix[(i - 1) * m + j].x = i;
      matrix[(i - 1) * m + j].y = j;
      matrix[(i - 1) * m + j].biao = (i - 1) * m + j;
      fa[(i - 1) * m + j] = (i - 1) * m + j;
    }
}
void debug() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cout << matrix[(i - 1) * m + j].num << " ";
    cout << endl;
  }
}
void ycl() {
  sort(matrix + 1, matrix + n * m + 1, cmp1);
  for (int i = 2; i <= n * m; i++)
    if (matrix[i].num == matrix[i - 1].num && matrix[i].x == matrix[i - 1].x)
      merge(matrix[i].biao, matrix[i - 1].biao);
  sort(matrix + 1, matrix + n * m + 1, cmp2);
  for (int i = 2; i <= m * n; i++)
    if (matrix[i].num == matrix[i - 1].num && matrix[i].y == matrix[i - 1].y)
      merge(matrix[i].biao, matrix[i - 1].biao);
}
void ycl2() {
  sort(matrix + 1, matrix + n * m + 1, cmp1);
  int tmp, tmp_next;
  for (int i = 1; i <= n * m; i++) {
    if (matrix[i].x != matrix[i - 1].x) {
      tmp = 0;
      tmp_next = 0;
    }
    if (matrix[i].num != matrix[tmp_next].num) {
      tmp = tmp_next;
      tmp_next = i;
      if (tmp != 0) {
        insert(getfather(matrix[tmp].biao), getfather(matrix[tmp_next].biao));
        ru[getfather(matrix[tmp_next].biao)]++;
      }
    }
  }
  sort(matrix + 1, matrix + n * m + 1, cmp2);
  for (int i = 1; i <= n * m; i++) {
    if (matrix[i].y != matrix[i - 1].y) {
      tmp = 0;
      tmp_next = 0;
    }
    if (matrix[i].num != matrix[tmp_next].num) {
      tmp = tmp_next;
      tmp_next = i;
      if (tmp != 0) {
        insert(getfather(matrix[tmp].biao), getfather(matrix[tmp_next].biao));
        ru[getfather(matrix[tmp_next].biao)]++;
      }
    }
  }
  sort(matrix + 1, matrix + n * m + 1, cmp3);
}
void work() {
  for (int i = 1; i <= n * m; i++)
    if (ru[getfather(i)] == 0) {
      q[++q[0]] = i;
      f[getfather(i)] = 1;
      flag[getfather(i)] = true;
    }
  int head = 0, now;
  while (head != q[0]) {
    now = q[++head];
    for (int p = link[now]; p; p = e[p].next) {
      f[e[p].num] = max(f[now] + 1, f[e[p].num]);
      ru[e[p].num]--;
      if (ru[e[p].num] == 0 && flag[e[p].num] == false) {
        q[++q[0]] = e[p].num;
        flag[e[p].num] = true;
      }
    }
  }
  for (int i = 1; i <= n * m; i++) f[i] = f[getfather(i)];
}
void output() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      printf("%d", f[(i - 1) * m + j]);
      if (j != m) printf(" ");
    }
    printf("\n");
  }
}
int main() {
  input();
  ycl();
  ycl2();
  work();
  output();
  return 0;
}
