#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1.0);
const int N = 1e6 + 5;
int par[N], siz[N];
vector<vector<int> > v;
int root(int x) {
  while (par[x] != -1) x = par[x];
  return x;
}
int dp[N];
int ind[N];
vector<int> adjlist[N];
void merge(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y) return;
  if (siz[y] < siz[x]) swap(x, y);
  siz[y] += siz[x];
  par[x] = y;
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n * m; ++i) {
    siz[i] = 1;
    par[i] = -1;
  }
  v.resize(n);
  for (int i = 0; i < n; ++i) {
    v[i].resize(m);
    for (int j = 0; j < m; ++j) cin >> v[i][j];
  }
  for (int i = 0; i < n; ++i) {
    map<int, vector<int> > occ;
    for (int j = 0; j < m; ++j) {
      occ[v[i][j]].push_back(j);
    }
    for (auto k : occ) {
      for (int j = 1; j < (int)k.second.size(); ++j) {
        merge(i * m + k.second[j], i * m + k.second[j - 1]);
      }
    }
  }
  for (int j = 0; j < m; ++j) {
    map<int, vector<int> > occ;
    for (int i = 0; i < n; ++i) {
      occ[v[i][j]].push_back(i);
    }
    for (auto k : occ) {
      for (int i = 1; i < (int)k.second.size(); ++i) {
        merge(m * k.second[i] + j, m * k.second[i - 1] + j);
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    vector<pair<int, int> > a;
    for (int j = 0; j < m; ++j) {
      a.push_back(make_pair(v[i][j], j));
    }
    sort(a.begin(), a.end());
    for (int j = 0; j < m; ++j) {
      auto it = lower_bound(a.begin(), a.end(), make_pair(a[j].first + 1, 0));
      if (it == a.end()) continue;
      adjlist[root(m * i + a[j].second)].push_back(root(m * i + it->second));
      ind[root(m * i + it->second)]++;
    }
  }
  for (int j = 0; j < m; ++j) {
    vector<pair<int, int> > a;
    for (int i = 0; i < n; ++i) {
      a.push_back(make_pair(v[i][j], i));
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < n; ++i) {
      auto it = lower_bound(a.begin(), a.end(), make_pair(a[i].first + 1, 0));
      if (it == a.end()) continue;
      adjlist[root(m * a[i].second + j)].push_back(root(m * (it->second) + j));
      ind[root(m * (it->second) + j)]++;
    }
  }
  queue<int> q;
  for (int i = 0; i < n * m; ++i)
    if (ind[i] == 0) q.push(i);
  while (!q.empty()) {
    int k = q.front();
    q.pop();
    for (int i : adjlist[k]) {
      dp[i] = max(dp[i], dp[k] + 1);
      ind[i]--;
      if (ind[i] == 0) {
        q.push(i);
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cout << dp[root(i * m + j)] + 1 << ' ';
    }
    cout << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
