#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > row[1000005], col[1000005], V;
vector<int> gr[1000005], eq[1000005];
bool used[1000005], vis[1000005];
int _equal[1000005], ne[1000005], ans[1000005];
int e;
void dfs(int ver) {
  if (used[ver]) {
    return;
  }
  used[ver] = true;
  _equal[ver] = e;
  for (auto v : eq[ver]) {
    dfs(v);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, rw = 0;
  cin >> n >> m;
  int tot = n * m;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      int num;
      cin >> num;
      row[i].push_back(make_pair(num, rw + j));
      col[j].push_back(make_pair(num, rw + j));
      V.push_back(make_pair(num, rw + j));
    }
    rw += m;
  }
  for (long long int i = 0; i < n; i++) {
    sort(row[i].begin(), row[i].end());
    for (int j = 1; j <= m - 1; j++) {
      if (row[i][j].first > row[i][j - 1].first) {
        gr[row[i][j - 1].second].push_back(row[i][j].second);
      } else {
        eq[row[i][j - 1].second].push_back(row[i][j].second);
        eq[row[i][j].second].push_back(row[i][j - 1].second);
        vis[row[i][j - 1].second] = vis[row[i][j].second] = true;
      }
    }
  }
  for (long long int j = 0; j < m; j++) {
    sort(col[j].begin(), col[j].end());
    for (int i = 1; i <= n - 1; i++) {
      if (col[j][i].first > col[j][i - 1].first) {
        gr[col[j][i - 1].second].push_back(col[j][i].second);
      } else {
        eq[col[j][i - 1].second].push_back(col[j][i].second);
        eq[col[j][i].second].push_back(col[j][i - 1].second);
        vis[col[j][i].second] = vis[col[j][i - 1].second] = true;
      }
    }
  }
  for (long long int i = 0; i < tot; i++) {
    if (vis[i] and !used[i]) {
      dfs(i);
      ++e;
    }
  }
  sort(V.begin(), V.end());
  for (long long int j = 0; j < tot; j++) {
    int i = V[j].second;
    int q = (vis[i] ? ne[_equal[i]] : ans[i]);
    for (auto v : gr[i]) {
      if (vis[v]) {
        ne[_equal[v]] = max(ne[_equal[v]], q + 1);
      } else {
        ans[v] = max(ans[v], q + 1);
      }
    }
  }
  for (long long int i = 0; i < tot; i++) {
    cout << 1 + (vis[i] ? ne[_equal[i]] : ans[i]);
    cout << ((i + 1) % m ? " " : "\n");
  }
  return 0;
}
