#include <bits/stdc++.h>
using namespace std;
int N, M, tot, l, r, pt, len;
int a[1000010], b[1000010], pre[1000010], mark[1000010], num[1000010],
    q[1000010], in[1000010];
int nex[4][1000010];
bool visited[1000010];
int st[1000010], ne[2000010], go[2000010];
void Add(int x, int y) {
  ne[++pt] = st[x];
  st[x] = pt;
  go[pt] = y;
}
bool cmp(const int &A, const int &B) { return a[A] < a[B]; }
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) scanf("%d", &a[i * M + j]);
  memcpy(b, a, sizeof(b));
  sort(b, b + N * M);
  len = unique(b, b + N * M) - b;
  for (int i = 0; i < N * M; i++) a[i] = lower_bound(b, b + len, a[i]) - b;
  memset(pre, 255, sizeof(pre));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      nex[0][i * M + j] = pre[a[i * M + j]];
      pre[a[i * M + j]] = i * M + j;
    }
    for (int j = 0; j < M; j++) pre[a[i * M + j]] = -1;
    for (int j = M - 1; j >= 0; j--) {
      nex[1][i * M + j] = pre[a[i * M + j]];
      pre[a[i * M + j]] = i * M + j;
    }
    for (int j = 0; j < M; j++) pre[a[i * M + j]] = -1;
  }
  for (int j = 0; j < M; j++) {
    for (int i = 0; i < N; i++) {
      nex[2][i * M + j] = pre[a[i * M + j]];
      pre[a[i * M + j]] = i * M + j;
    }
    for (int i = 0; i < N; i++) pre[a[i * M + j]] = -1;
    for (int i = N - 1; i >= 0; i--) {
      nex[3][i * M + j] = pre[a[i * M + j]];
      pre[a[i * M + j]] = i * M + j;
    }
    for (int i = 0; i < N; i++) pre[a[i * M + j]] = -1;
  }
  for (int i = 0; i < N * M; i++)
    if (!visited[i]) {
      ++tot;
      for (visited[i] = 1, q[l = r = 0] = i; l <= r; l++) {
        int x = q[l];
        mark[x] = tot;
        for (int j = 0; j < 4; j++) {
          int tt = nex[j][x];
          if (visited[tt] || a[x] != a[tt]) continue;
          q[++r] = tt;
          visited[tt] = 1;
        }
      }
    }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) q[j] = i * M + j;
    sort(q, q + M, cmp);
    for (int j = 1; j < M; j++) {
      int x = mark[q[j - 1]];
      int y = mark[q[j]];
      if (x == y) continue;
      Add(x, y);
      in[y]++;
    }
  }
  for (int j = 0; j < M; j++) {
    for (int i = 0; i < N; i++) q[i] = i * M + j;
    sort(q, q + N, cmp);
    for (int i = 1; i < N; i++) {
      int x = mark[q[i - 1]];
      int y = mark[q[i]];
      if (x == y) continue;
      Add(x, y);
      in[y]++;
    }
  }
  l = 1;
  r = 0;
  for (int i = 1; i <= tot; i++)
    if (!in[i]) num[i] = 1, q[++r] = i;
  for (; l <= r; l++) {
    int x = q[l];
    for (int i = st[x]; i; i = ne[i]) {
      in[go[i]]--;
      num[go[i]] = max(num[go[i]], num[x] + 1);
      if (!in[go[i]]) q[++r] = go[i];
    }
  }
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) {
      printf("%d", num[mark[i * M + j]]);
      if (j + 1 < M)
        printf(" ");
      else
        printf("\n");
    }
}
