#include <bits/stdc++.h>
using namespace std;
int p[1 << 20], dp[1 << 20], a[1 << 20], pos[1 << 20], n, m;
vector<int> g[1 << 20];
vector<pair<int, int>> mc[1 << 20], mr[1 << 20];
vector<vector<int>> cg[1 << 20];
bitset<1000001> vis;
int Find(int x) { return x == p[x] ? p[x] : p[x] = Find(p[x]); }
int main() {
  cin >> n >> m;
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n)))
    for (__typeof(m) j = (0) - ((0) > (m)); j != (m) - ((0) > (m));
         j += 1 - 2 * ((0) > (m))) {
      scanf("%d", &a[i * m + j]);
      pos[i * m + j] = i * m + j;
      mc[j].push_back({a[i * m + j], i * m + j});
      mr[i].push_back({a[i * m + j], i * m + j});
      p[i * m + j] = i * m + j;
    }
  sort(pos, pos + n * m, [&](int x, int y) { return a[x] < a[y]; });
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n)))
    sort(mr[i].begin(), mr[i].end());
  for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m));
       i += 1 - 2 * ((0) > (m)))
    sort(mc[i].begin(), mc[i].end());
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n)))
    for (__typeof(m) j = (1) - ((1) > (m)); j != (m) - ((1) > (m));
         j += 1 - 2 * ((1) > (m))) {
      if (a[Find(mr[i][j].second)] == a[Find(mr[i][j - 1].second)])
        p[Find(mr[i][j - 1].second)] = p[Find(mr[i][j].second)];
      else
        g[mr[i][j].second].push_back(mr[i][j - 1].second);
    }
  for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m));
       i += 1 - 2 * ((0) > (m)))
    for (__typeof(n) j = (1) - ((1) > (n)); j != (n) - ((1) > (n));
         j += 1 - 2 * ((1) > (n))) {
      if (a[Find(mc[i][j].second)] == a[Find(mc[i][j - 1].second)])
        p[Find(mc[i][j - 1].second)] = p[Find(mc[i][j].second)];
      else
        g[mc[i][j].second].push_back(mc[i][j - 1].second);
    }
  for (__typeof(n * m) i = (0) - ((0) > (n * m));
       i != (n * m) - ((0) > (n * m)); i += 1 - 2 * ((0) > (n * m)))
    if (!g[i].empty()) cg[Find(i)].push_back(g[i]);
  for (__typeof(n * m) i = (0) - ((0) > (n * m));
       i != (n * m) - ((0) > (n * m)); i += 1 - 2 * ((0) > (n * m))) {
    int v = Find(pos[i]);
    if (!vis[v]) {
      dp[v] = 1;
      for (auto gg : cg[v])
        for (auto u : gg) dp[v] = max(dp[v], dp[Find(u)] + 1);
      vis[v] = true;
    }
  }
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n))) {
    for (__typeof(m) j = (0) - ((0) > (m)); j != (m) - ((0) > (m));
         j += 1 - 2 * ((0) > (m)))
      cout << dp[Find(i * m + j)] << " ";
    cout << "\n";
  }
}
