#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, m, val[2][N], ans[N], fa[N], id[N], a[N];
bool cmp(int x, int y) { return a[x] < a[y]; }
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n * m; ++i) scanf("%d", &a[i]), fa[i] = id[i] = i;
  sort(id + 1, id + n * m + 1, cmp);
  for (int i = 1; i <= n * m; ++i) {
    int x = (id[i] - 1) / m + 1, y = (id[i] - 1) % m + 1;
    int px = find(val[0][x]), py = find(val[1][y]), p = find(id[i]);
    ans[p] = max(ans[px] + (a[p] > a[px]), ans[py] + (a[p] > a[py]));
    if (a[p] == a[px]) fa[px] = p;
    if (a[p] == a[py]) fa[py] = p;
    val[0][x] = val[1][y] = p;
  }
  for (int i = 1; i <= n; ++i, puts(""))
    for (int j = 1; j <= m; ++j) printf("%d ", ans[find((i - 1) * m + j)]);
  return 0;
}
