#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int nax = 1000000 + 10;
int n, m, dp[nax], visited[nax], par[nax], s[nax];
vector<pair<int, int> > rows[nax], col[nax];
vector<int> graph[nax], V;
int findi(int a) {
  int temp = a;
  while (a != par[a]) a = par[a];
  return par[temp] = a;
}
void join(int a, int b) {
  a = findi(a);
  b = findi(b);
  if (s[a] < s[b]) swap(a, b);
  s[a] += s[b];
  par[b] = a;
}
void dfs(int v) {
  visited[v] = 1;
  for (auto x : graph[v])
    if (visited[x] == 0) dfs(x);
  V.push_back(v);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int num;
      cin >> num;
      int node = i * m + j;
      rows[i].push_back({num, node});
      col[j].push_back({num, node});
    }
  }
  for (int i = 0; i < n; i++) sort(rows[i].begin(), rows[i].end());
  for (int i = 0; i < m; i++) sort(col[i].begin(), col[i].end());
  for (int i = 0; i < n * m; i++) par[i] = i;
  for (int i = 0; i < n * m; i++) s[i] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < m; j++) {
      if (rows[i][j].first == rows[i][j - 1].first)
        join(rows[i][j].second, rows[i][j - 1].second);
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 1; j < n; j++) {
      if (col[i][j].first == col[i][j - 1].first)
        join(col[i][j].second, col[i][j - 1].second);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < m; j++) {
      if (rows[i][j].first != rows[i][j - 1].first) {
        int node1 = rows[i][j].second;
        int node2 = rows[i][j - 1].second;
        node1 = findi(node1);
        node2 = findi(node2);
        graph[node2].push_back(node1);
      }
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 1; j < n; j++) {
      if (col[i][j].first != col[i][j - 1].first) {
        int node1 = col[i][j].second;
        int node2 = col[i][j - 1].second;
        node1 = findi(node1);
        node2 = findi(node2);
        graph[node2].push_back(node1);
      }
    }
  }
  for (int i = 0; i < n * m; i++)
    if (visited[i] == 0 && findi(i) == i) dfs(i);
  reverse(V.begin(), V.end());
  for (auto x : V) {
    if (dp[x] == 0) dp[x] = 1;
    for (auto y : graph[x]) dp[y] = max(dp[y], 1 + dp[x]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int curnode = i * m + j;
      curnode = findi(curnode);
      cout << dp[curnode] << " ";
    }
    cout << endl;
  }
  return 0;
}
