#include <bits/stdc++.h>
using namespace std;
int n, m, hea[5000000], wen[5000000], nex[5000000], ans[3000000], lr[3000000],
    len, bo[3000000], boo;
struct arr {
  int a, x, y, fa, num;
} a[3000000];
struct arrr {
  int fa, num;
} c[3000000];
bool cmp1(arr x, arr y) {
  return ((x.a < y.a) || ((x.a == y.a) && (x.x < y.x)));
}
bool cmp4(arr x, arr y) {
  return ((x.a < y.a) || ((x.a == y.a) && (x.y < y.y)));
}
bool cmp2(arr x, arr y) { return x.num < y.num; }
bool cmp3(arr x, arr y) {
  return ((x.y < y.y) || ((x.y == y.y) && (x.x < y.x)));
}
void add(int x, int y) {
  ++len;
  nex[len] = hea[x];
  wen[len] = y;
  hea[x] = len;
}
int find(int x) {
  if (c[x].fa == x) return x;
  c[x].fa = find(c[x].fa);
  return c[x].fa;
}
void topo() {
  int l = 1, r = 0;
  for (int i = 1; i <= n * m; i++)
    if (!bo[i] && find(i) == i) {
      ++r;
      lr[r] = i;
      ans[i] = 1;
    }
  do {
    for (int i = hea[lr[l]]; i; i = nex[i])
      if (bo[wen[i]]) {
        --bo[wen[i]];
        ans[wen[i]] = ans[lr[l]] + 1;
        if (!bo[wen[i]]) {
          ++r;
          lr[r] = wen[i];
        }
      }
    ++l;
  } while (l <= r);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int x;
      scanf("%d", &x);
      if (i == 1 && j == 1) boo = x;
      a[i * m - m + j] = {x, i, j, i * m - m + j, i * m - m + j};
      c[i * m - m + j] = {i * m - m + j, i * m - m + j};
    }
  for (int i = 1; i <= n; i++) {
    sort(a + i * m - m + 1, a + i * m + 1, cmp1);
    for (int j = 2; j <= m; j++) {
      int t = i * m - m + j;
      if (a[t].a == a[t - 1].a) c[find(a[t].num)].fa = find(a[t - 1].num);
    }
  }
  sort(a + 1, a + n * m + 1, cmp3);
  for (int i = 1; i <= m; i++) {
    sort(a + i * n - n + 1, a + i * n + 1, cmp4);
    for (int j = 2; j <= n; j++) {
      int t = i * n + j - n;
      if (a[t].a == a[t - 1].a) c[find(a[t].num)].fa = find(a[t - 1].num);
    }
  }
  sort(a + 1, a + n * m + 1, cmp2);
  for (int i = 1; i <= n; i++) {
    sort(a + i * m - m + 1, a + i * m + 1, cmp1);
    for (int j = 2; j <= m; j++) {
      int t = i * m - m + j;
      if (a[t].a != a[t - 1].a)
        add(find(a[t - 1].num), find(a[t].num)), ++bo[find(a[t].num)];
    }
  }
  sort(a + 1, a + n * m + 1, cmp3);
  for (int i = 1; i <= m; i++) {
    sort(a + i * n - n + 1, a + i * n + 1, cmp4);
    for (int j = 2; j <= n; j++) {
      int t = i * n + j - n;
      if (a[t].a != a[t - 1].a)
        add(find(a[t - 1].num), find(a[t].num)), ++bo[find(a[t].num)];
    }
  }
  topo();
  for (int i = 1; i <= n * m; i++) ans[i] = ans[find(i)];
  for (int i = 1; i <= n * m; i++) {
    printf("%d ", ans[i]);
    if (i % m == 0) printf("\n");
  }
}
