#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 100;
const long long inf = (1LL << 30 - 1);
pair<int, int> A[maxn];
int fa[maxn], X[maxn], Y[maxn], Hx[maxn], Hy[maxn], ans[maxn];
int FindSet(int x) { return fa[x] == x ? x : fa[x] = FindSet(fa[x]); }
void UnionSet(int u, int v) {
  u = FindSet(u);
  v = FindSet(v);
  if (u != v) fa[u] = v;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n * m; i++) {
    fa[i] = i;
    scanf("%d", &A[i].first);
    A[i].second = i;
  }
  sort(A, A + n * m);
  int j = -1;
  memset(X, 0, sizeof(X));
  memset(Y, 0, sizeof(Y));
  for (int i = 0; i < n * m; i++) {
    if (i != n * m - 1 && A[i].first == A[i + 1].first) continue;
    for (int k = j + 1; k <= i; k++) {
      int p = A[k].second;
      int x = A[k].second / m, y = A[k].second % m;
      Hx[x] = p;
      Hy[y] = p;
    }
    for (int k = j + 1; k <= i; k++) {
      int p = A[k].second;
      int x = A[k].second / m, y = A[k].second % m;
      UnionSet(Hx[x], p);
      UnionSet(Hy[y], p);
    }
    for (int k = j + 1; k <= i; k++) {
      int p = A[k].second;
      int x = A[k].second / m, y = A[k].second % m;
      int pa = FindSet(p);
      ans[pa] = max(ans[pa], max(X[x], Y[y]) + 1);
    }
    for (int k = j + 1; k <= i; k++) {
      int p = A[k].second;
      int x = A[k].second / m, y = A[k].second % m;
      int pa = FindSet(p);
      X[x] = max(X[x], ans[pa]);
      Y[y] = max(Y[y], ans[pa]);
    }
    j = i;
  }
  for (int i = 0; i < n * m; i++) {
    printf("%d", ans[FindSet(i)]);
    if ((i + 1) % m == 0)
      printf("\n");
    else
      printf(" ");
  }
  return 0;
}
