#include <bits/stdc++.h>
using namespace std;
int a[1000010], k;
vector<int> g[1000010];
vector<int> gh[1000010];
int comp[1000010], d[1000010];
bool used[1000010];
void dfs(int x) {
  comp[x] = k;
  int i;
  for (i = 0; i < gh[x].size(); i++)
    if (comp[gh[x][i]] == -1) dfs(gh[x][i]);
}
vector<int> order;
void dfs2(int x) {
  used[x] = true;
  int i;
  for (i = 0; i < g[x].size(); i++)
    if (!used[g[x][i]]) dfs2(g[x][i]);
  order.push_back(x);
}
int ans[1000010];
int main() {
  int n, m, i, j, x;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n * m; i++) scanf("%d", &a[i]);
  vector<vector<pair<int, int> > > b(n), c(m);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) b[i].push_back({a[i * m + j], i * m + j});
    sort(b[i].begin(), b[i].end());
    for (j = 0; j < m - 1; j++) {
      if (b[i][j].first == b[i][j + 1].first) {
        gh[b[i][j].second].push_back(b[i][j + 1].second);
        gh[b[i][j + 1].second].push_back(b[i][j].second);
      }
    }
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) c[i].push_back({a[j * m + i], j * m + i});
    sort(c[i].begin(), c[i].end());
    for (j = 0; j < n - 1; j++) {
      if (c[i][j].first == c[i][j + 1].first) {
        gh[c[i][j].second].push_back(c[i][j + 1].second);
        gh[c[i][j + 1].second].push_back(c[i][j].second);
      }
    }
  }
  fill(comp, comp + n * m + 1, -1);
  for (i = 0; i < n * m; i++)
    if (!gh[i].empty() && comp[i] == -1) {
      k++;
      dfs(i);
    }
  for (i = 0; i < n * m; i++)
    if (comp[i] == -1) comp[i] = ++k;
  for (i = 0; i < n; i++)
    for (j = 0; j < m - 1; j++)
      if (comp[b[i][j].second] != comp[b[i][j + 1].second])
        g[comp[b[i][j].second]].push_back(comp[b[i][j + 1].second]);
  for (i = 0; i < m; i++)
    for (j = 0; j < n - 1; j++)
      if (comp[c[i][j].second] != comp[c[i][j + 1].second])
        g[comp[c[i][j].second]].push_back(comp[c[i][j + 1].second]);
  x = 0;
  for (i = 0; i < n * m; i++)
    if (!used[comp[i]]) dfs2(comp[i]);
  reverse(order.begin(), order.end());
  for (i = 0; i < order.size(); i++)
    for (j = 0; j < g[order[i]].size(); j++)
      ans[g[order[i]][j]] = max(ans[g[order[i]][j]], ans[order[i]] + 1);
  for (i = 0; i < n * m; i++) {
    if (i != 0 && i % m == 0) printf("\n");
    printf("%d ", ans[comp[i]] + 1);
  }
  printf("\n");
  return 0;
}
