#include <bits/stdc++.h>
using namespace std;
int H, v, P[1000005], W, Z[1000005], X[1000005];
vector<pair<int, int>> R[1000005], C[1000005];
vector<int> E[1000005], V;
void d(int n) {
  if (Z[n]) return;
  Z[n] = 1;
  for (int v : E[n]) d(v);
  V.push_back(n);
}
int q(int n) { return P[n] == n ? n : P[n] = q(P[n]); }
void g(int a, int b) { P[q(a)] = q(b); }
int main() {
  cin >> H >> W;
  for (int i = 0; i <= H - 1; i++)
    for (int j = 0; j <= W - 1; j++) {
      P[i * W + j] = i * W + j, scanf("%d", &v);
      R[i].push_back({v, i * W + j}), C[j].push_back({v, i * W + j});
    }
  for (int i = 0; i <= 1000000; i++)
    sort(R[i].begin(), R[i].end()), sort(C[i].begin(), C[i].end());
  for (int i = 0; i <= H - 1; i++)
    for (int j = 1; j <= W - 1; j++)
      if (R[i][j].first == R[i][j - 1].first)
        g(R[i][j].second, R[i][j - 1].second);
  for (int i = 0; i <= W - 1; i++)
    for (int j = 1; j <= H - 1; j++)
      if (C[i][j].first == C[i][j - 1].first)
        g(C[i][j].second, C[i][j - 1].second);
  for (int i = 0; i <= H - 1; i++)
    for (int j = 1; j <= W - 1; j++)
      if (R[i][j].first != R[i][j - 1].first)
        E[q(R[i][j - 1].second)].push_back(q(R[i][j].second));
  for (int i = 0; i <= W - 1; i++)
    for (int j = 1; j <= H - 1; j++)
      if (C[i][j].first != C[i][j - 1].first)
        E[q(C[i][j - 1].second)].push_back(q(C[i][j].second));
  for (int i = 0; i <= H * W - 1; i++)
    if (q(i) == i && !Z[i]) d(i);
  reverse(V.begin(), V.end());
  for (int v : V) {
    X[v] = max(X[v], 1);
    for (int w : E[v]) X[w] = max(X[w], X[v] + 1);
  }
  for (int i = 0; i <= H - 1; i++) {
    for (int j = 0; j <= W - 1; j++) printf("%d ", X[q(i * W + j)]);
    printf("\n");
  }
}
