#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000005;
int N, M;
vector<vector<int> > A;
vector<vector<pair<int, int> > > row, col;
vector<pair<int, int> > adj[MAX];
queue<int> q;
int com[MAX];
int idx = 0;
int indeg[MAX];
vector<pair<int, int> > nadj[MAX];
int ans[MAX];
bool vis[MAX];
vector<int> order;
void bfs(int node) {
  q.push(node);
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    if (com[cur] != 0) continue;
    com[cur] = idx;
    for (int i = 0; i < adj[cur].size(); i++) {
      int next = adj[cur][i].first;
      if (adj[cur][i].second == 0 && com[next] == 0) q.push(next);
    }
  }
}
void dfs(int cur) {
  vis[cur] = true;
  for (int i = 0; i < nadj[cur].size(); i++) {
    int next = nadj[cur][i].first;
    if (!vis[next]) dfs(next);
  }
  order.push_back(cur);
}
void longest_path(int root) {
  memset(ans, -1, sizeof(ans));
  ans[root] = 0;
  for (int i = (int)order.size() - 1; i >= 0; i--) {
    int cur = order[i];
    for (int j = 0; j < nadj[cur].size(); j++) {
      int next = nadj[cur][j].first;
      ans[next] = max(ans[next], ans[cur] + nadj[cur][j].second);
    }
  }
}
int main() {
  scanf("%d %d", &N, &M);
  A = vector<vector<int> >(N, vector<int>(M));
  row = vector<vector<pair<int, int> > >(N, vector<pair<int, int> >(M));
  col = vector<vector<pair<int, int> > >(M, vector<pair<int, int> >(N));
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) {
      scanf("%d", &A[i][j]);
      row[i][j] = make_pair(A[i][j], i * M + j);
      col[j][i] = make_pair(A[i][j], i * M + j);
    }
  for (int i = 0; i < N; i++) {
    sort(row[i].begin(), row[i].end());
    for (int j = 0; j < M - 1; j++) {
      if (row[i][j].first == row[i][j + 1].first) {
        adj[row[i][j].second].push_back(make_pair(row[i][j + 1].second, 0));
        adj[row[i][j + 1].second].push_back(make_pair(row[i][j].second, 0));
      } else
        adj[row[i][j].second].push_back(make_pair(row[i][j + 1].second, 1));
    }
  }
  for (int j = 0; j < M; j++) {
    sort(col[j].begin(), col[j].end());
    for (int i = 0; i < N - 1; i++) {
      if (col[j][i].first == col[j][i + 1].first) {
        adj[col[j][i].second].push_back(make_pair(col[j][i + 1].second, 0));
        adj[col[j][i + 1].second].push_back(make_pair(col[j][i].second, 0));
      } else
        adj[col[j][i].second].push_back(make_pair(col[j][i + 1].second, 1));
    }
  }
  for (int i = 0; i < N * M; i++)
    if (com[i] == 0) {
      idx++;
      bfs(i);
    }
  for (int i = 0; i < N * M; i++)
    for (int j = 0; j < adj[i].size(); j++) {
      if (com[i] == com[adj[i][j].first]) continue;
      nadj[com[i]].push_back(make_pair(com[adj[i][j].first], adj[i][j].second));
      indeg[com[adj[i][j].first]]++;
    }
  for (int i = 1; i <= idx; i++)
    if (indeg[i] == 0) nadj[0].push_back(make_pair(i, 1));
  dfs(0);
  longest_path(0);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) printf("%d ", ans[com[i * M + j]]);
    printf("\n");
  }
  return 0;
}
