#include <bits/stdc++.h>
using namespace std;
const int maxn = 2311111;
int n, m, a[maxn], fa[maxn];
int get(int x) {
  if (fa[x] == x) return x;
  return fa[x] = get(fa[x]);
}
struct node {
  int i, j;
  bool operator<(const node &b) const {
    return a[(i - 1) * m + j] < a[(b.i - 1) * m + b.j];
  }
} p[maxn];
int lmin[maxn], cmin[maxn], ans[maxn];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[(i - 1) * m + j];
      p[(i - 1) * m + j] = (node){i, j};
      fa[(i - 1) * m + j] = (i - 1) * m + j;
    }
  }
  sort(p + 1, p + 1 + n * m);
  for (int i = 1; i <= n * m; i++) {
    int x = p[i].i, y = p[i].j;
    int id = (x - 1) * m + y;
    int fx = get(lmin[x]), fy = get(cmin[y]);
    ans[id] = max(ans[fx] + (a[fx] < a[id]), ans[fy] + (a[fy] < a[id]));
    if (a[fx] == a[id]) fa[fx] = id;
    if (a[fy] == a[id]) fa[fy] = id;
    lmin[x] = cmin[y] = id;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cout << ans[get((i - 1) * m + j)] << ' ';
    }
    cout << endl;
  }
  return 0;
}
