#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int Mod = 1000000007;
const int maxn = 1e6 + 10;
const double eps = 1e-8;
const double PI = acos(-1.0);
struct point {
  int x, y;
  int v;
  bool operator<(const point& rhs) const { return v < rhs.v; }
} p[maxn];
int a[maxn];
int fa[maxn], ans[maxn];
int maxx[maxn], maxy[maxn];
int find(int x) { return fa[x] == x ? x : (fa[x] = find(fa[x])); }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      ++cnt;
      scanf("%d", &a[cnt]);
      p[cnt].x = i;
      p[cnt].y = j;
      p[cnt].v = a[cnt];
    }
  }
  for (int i = 1; i <= cnt; i++) fa[i] = i;
  sort(p + 1, p + 1 + cnt);
  for (int i = 1; i <= cnt; i++) {
    int x = p[i].x, y = p[i].y, v = p[i].v;
    int id = (x - 1) * m + y;
    int tx = 0, ty = 0;
    int fx = find(maxx[x]);
    int fy = find(maxy[y]);
    if (v > a[fx]) tx++;
    if (v > a[fy]) ty++;
    ans[id] = max(ans[fx] + tx, ans[fy] + ty);
    if (v == a[fx]) {
      int f = find(id);
      if (ans[f] > ans[fx])
        fa[fx] = f;
      else
        fa[f] = fx;
    }
    if (v == a[fy]) {
      int f = find(id);
      if (ans[f] > ans[fy])
        fa[fy] = f;
      else
        fa[f] = fy;
    }
    maxx[x] = maxy[y] = find(id);
  }
  cnt = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) printf("%d ", ans[find(++cnt)]);
    printf("\n");
  }
  return 0;
}
