#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 5e5 + 5;
vector<vector<int> > a, sz, ans;
vector<int> mxi, mxj;
vector<vector<pii> > p;
pii get_par(int i, int j) {
  if (make_pair(i, j) == p[i][j]) return p[i][j];
  return p[i][j] = get_par(p[i][j].first, p[i][j].second);
}
void unite_set(pii a, pii b) {
  a = get_par(a.first, a.second), b = get_par(b.first, b.second);
  if (a == b) return;
  if (sz[a.first][a.second] < sz[b.first][b.second]) swap(a, b);
  p[b.first][b.second] = a;
  sz[a.first][a.second] += sz[b.first][b.second];
}
int main() {
  ios ::sync_with_stdio(0), cin.tie(0);
  int n, m;
  cin >> n >> m;
  a.resize(n);
  sz.resize(n);
  ans.resize(n);
  p.resize(n);
  mxi.resize(n);
  mxj.resize(m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      a[i].push_back(0);
      cin >> a[i][j];
      p[i].push_back({0, 0});
      sz[i].push_back(0);
      ans[i].push_back(0);
      p[i][j] = {i, j};
      sz[i][j] = 1;
      ans[i][j] = 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    unordered_map<int, int> last;
    for (int j = 0; j < m; ++j) {
      if (last[a[i][j]]) unite_set({i, last[a[i][j]] - 1}, {i, j});
      last[a[i][j]] = j + 1;
    }
  }
  for (int j = 0; j < m; ++j) {
    unordered_map<int, int> last;
    for (int i = 0; i < n; ++i) {
      if (last[a[i][j]]) unite_set({last[a[i][j]] - 1, j}, {i, j});
      last[a[i][j]] = i + 1;
    }
  }
  vector<int> vals;
  unordered_map<int, vector<pii> > pos;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      vals.push_back(a[i][j]);
      pos[a[i][j]].push_back({i, j});
    }
  }
  sort(vals.begin(), vals.end());
  for (int q = 0; q < vals.size(); ++q) {
    if (q && vals[q] == vals[q - 1]) continue;
    for (auto i : pos[vals[q]]) {
      pii par = get_par(i.first, i.second);
      ans[par.first][par.second] =
          max(ans[par.first][par.second], max(mxi[i.first], mxj[i.second]) + 1);
    }
    for (auto i : pos[vals[q]]) {
      pii par = get_par(i.first, i.second);
      mxi[i.first] = max(mxi[i.first], ans[par.first][par.second]);
      mxj[i.second] = max(mxj[i.second], ans[par.first][par.second]);
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      pii par = get_par(i, j);
      cout << ans[par.first][par.second] << ' ';
    }
    cout << '\n';
  }
  return 0;
}
