#include <bits/stdc++.h>
using namespace std;
int n, m;
const int MAXN = 1e6 + 10;
pair<int, pair<int, int> > A[MAXN];
int HX[MAXN], HY[MAXN];
int fa[MAXN];
int X[MAXN], Y[MAXN];
int ans[MAXN];
int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); }
void uni(int x, int y) {
  int fx = Find(x), fy = Find(y);
  if (fx != fy) {
    fa[fx] = fy;
  }
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 0; i < n * m; i++) {
      fa[i] = i;
    }
    for (int i = 0; i < n * m; i++) {
      scanf("%d", &A[i].first);
      A[i].second.first = i / m;
      A[i].second.second = i % m;
    }
    sort(A, A + n * m);
    memset(ans, 0, sizeof(ans));
    int j = -1;
    for (int i = j + 1; i < n * m; i++) {
      if (i + 1 < n * m && A[i].first == A[i + 1].first) continue;
      for (int k = j + 1; k <= i; k++) {
        int p = A[k].second.first * m + A[k].second.second;
        int x = A[k].second.first, y = A[k].second.second;
        HX[x] = p;
        HY[y] = p;
      }
      for (int k = j + 1; k <= i; k++) {
        int p = A[k].second.first * m + A[k].second.second;
        int x = A[k].second.first, y = A[k].second.second;
        uni(HX[x], p);
        uni(HY[y], p);
      }
      for (int k = j + 1; k <= i; k++) {
        int p = A[k].second.first * m + A[k].second.second;
        int x = A[k].second.first, y = A[k].second.second;
        int fp = Find(p);
        ans[fp] = max(ans[fp], max(X[x], Y[y]) + 1);
      }
      for (int k = j + 1; k <= i; k++) {
        int p = A[k].second.first * m + A[k].second.second;
        int x = A[k].second.first, y = A[k].second.second;
        int fp = Find(p);
        X[x] = max(X[x], ans[fp]);
        Y[y] = max(Y[y], ans[fp]);
      }
      j = i;
    }
    for (int i = 0; i < n * m; i++) {
      printf("%d ", ans[Find(i)]);
      if (i % m == m - 1) puts("");
    }
  }
}
