#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
struct dt {
  int v, c, r, id;
} a[N];
int n, m, curr[N], curc[N], pa[N], ans[N], t[N];
bool cmp(dt a, dt b) { return a.v < b.v; }
int Find(int u) {
  if (pa[u] == u) return u;
  return pa[u] = Find(pa[u]);
}
void Input() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int id = (i - 1) * m + j;
      cin >> a[id].v;
      t[id] = a[id].v;
      a[id].id = id;
      a[id].c = i;
      a[id].r = j;
      pa[id] = id;
    }
  }
}
void solve() {
  sort(a + 1, a + 1 + m * n, cmp);
  for (int i = 1; i <= n * m; i++) {
    int rr = Find(curr[a[i].r]);
    int cc = Find(curc[a[i].c]);
    ans[a[i].id] = max(ans[cc] + (a[i].v > t[cc]), ans[rr] + (a[i].v > t[rr]));
    if (a[i].v == t[cc]) pa[cc] = a[i].id;
    if (a[i].v == t[rr]) pa[rr] = a[i].id;
    curr[a[i].r] = a[i].id;
    curc[a[i].c] = a[i].id;
  }
  for (int i = 1; i <= n * m; i++) {
    cout << ans[Find(i)] << " ";
    if (i % m == 0) cout << "\n";
  }
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  Input();
  solve();
  return 0;
}
