#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
inline int in() {
  int x = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x;
}
struct Node {
  int x, y, v;
  Node() {}
  Node(int a, int b, int c) { x = a, y = b, v = c; }
} s[maxn];
int n, m, tot;
int a[maxn], b[maxn];
int row_mx[maxn], cur_mx[maxn];
int p[maxn];
bool cmp(const Node &A, const Node &B) { return A.v < B.v; }
inline int Find(int x) {
  int r = x, pre;
  while (r != p[r]) r = p[r];
  while (x != r) {
    pre = p[x], p[x] = r, x = pre;
  }
  return r;
}
int main() {
  n = in();
  m = in();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) a[++tot] = in(), s[tot] = Node(i, j, a[tot]);
  sort(s + 1, s + tot + 1, cmp);
  for (int i = 1; i <= tot; i++) p[i] = i;
  for (int i = 1; i <= tot; i++) {
    int x = s[i].x, y = s[i].y, v = s[i].v;
    int id = (x - 1) * m + y, t1 = 0, t2 = 0;
    int fx = Find(row_mx[x]), fy = Find(cur_mx[y]);
    if (v > a[fx]) t1++;
    if (v > a[fy]) t2++;
    b[id] = max(b[fx] + t1, b[fy] + t2);
    if (v == a[fx]) {
      int f = Find(id);
      if (b[f] > b[fx])
        p[fx] = f;
      else
        p[f] = fx;
    }
    if (v == a[fy]) {
      int f = Find(id);
      if (b[f] > b[fy])
        p[fy] = f;
      else
        p[f] = fy;
    }
    row_mx[x] = cur_mx[y] = Find(id);
  }
  int ip = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) printf("%d ", b[Find(++ip)]);
    putchar('\n');
  }
  return 0;
}
