#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
pair<int, pair<int, int> > M[maxn];
int hx[maxn] = {0}, hy[maxn] = {0}, ans[maxn] = {0}, fa[maxn] = {0};
map<int, int> mx, my;
void join(int a, int b);
int fi(int x);
int main() {
  int i, n, m, j, p, x, y, k, pa;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n * m; i++) {
    fa[i] = i;
    scanf("%d", &M[i].first);
    M[i].second.first = i / m;
    M[i].second.second = i % m;
  }
  sort(M, M + n * m);
  j = -1;
  for (i = 0; i < n * m; i++) {
    if (i != n * m - 1 && M[i].first == M[i + 1].first) {
      continue;
    }
    for (k = j + 1; k <= i; k++) {
      int p = M[k].second.first * m + M[k].second.second;
      int x = M[k].second.first, y = M[k].second.second;
      hx[x] = p;
      hy[y] = p;
    }
    for (k = j + 1; k <= i; k++) {
      p = M[k].second.first * m + M[k].second.second;
      x = M[k].second.first, y = M[k].second.second;
      join(hx[x], p);
      join(hy[y], p);
    }
    for (k = j + 1; k <= i; k++) {
      p = M[k].second.first * m + M[k].second.second;
      x = M[k].second.first, y = M[k].second.second;
      pa = fi(p);
      ans[pa] = max(ans[pa], max(mx[x], my[y]) + 1);
    }
    for (k = j + 1; k <= i; k++) {
      p = M[k].second.first * m + M[k].second.second;
      x = M[k].second.first, y = M[k].second.second;
      pa = fi(p);
      mx[x] = max(mx[x], ans[pa]);
      my[y] = max(my[y], ans[pa]);
    }
    j = i;
  }
  for (i = 0; i < n * m; i++) {
    printf("%d", ans[fi(i)]);
    if (i % m == m - 1) {
      printf("\n");
    } else {
      printf(" ");
    }
  }
  return 0;
}
int fi(int x) { return fa[x] == x ? x : fa[x] = fi(fa[x]); }
void join(int a, int b) {
  int x, y;
  x = fi(a);
  y = fi(b);
  if (x != y) {
    fa[y] = x;
  }
}
