#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
const int N = 1000005;
int n, m;
int a[N], p[N], dp[N];
vector<int> g[N];
int find(int x) { return x == p[x] ? x : p[x] = find(p[x]); }
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
void unite(int x, int y) {
  x = find(x), y = find(y);
  if (rnd() & 1) swap(x, y);
  p[x] = y;
}
int f(int x) {
  if (dp[x] != 0) {
    return dp[x];
  }
  dp[x] = 1;
  for (auto v : g[x]) {
    dp[x] = max(dp[x], f(v) + 1);
  }
  return dp[x];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i * m + j];
    }
  }
  for (int i = 0; i < N; ++i) p[i] = i;
  for (int i = 0; i < n; ++i) {
    vector<int> vec;
    for (int j = 0; j < m; ++j) vec.push_back(i * m + j);
    sort(vec.begin(), vec.end(), [](int a, int b) { return ::a[a] > ::a[b]; });
    for (int j = 1; j < m; ++j) {
      if (a[vec[j]] == a[vec[j - 1]]) {
        unite(vec[j - 1], vec[j]);
      }
    }
  }
  for (int j = 0; j < m; ++j) {
    vector<int> vec;
    for (int i = 0; i < n; ++i) vec.push_back(i * m + j);
    sort(vec.begin(), vec.end(), [](int a, int b) { return ::a[a] > ::a[b]; });
    for (int i = 1; i < n; ++i) {
      if (a[vec[i]] == a[vec[i - 1]]) {
        unite(vec[i - 1], vec[i]);
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    vector<int> vec;
    for (int j = 0; j < m; ++j) vec.push_back(i * m + j);
    sort(vec.begin(), vec.end(), [](int a, int b) { return ::a[a] > ::a[b]; });
    for (int j = 1; j < m; ++j) {
      if (a[vec[j - 1]] != a[vec[j]]) {
        g[find(vec[j - 1])].push_back(find(vec[j]));
      }
    }
  }
  for (int j = 0; j < m; ++j) {
    vector<int> vec;
    for (int i = 0; i < n; ++i) vec.push_back(i * m + j);
    sort(vec.begin(), vec.end(), [](int a, int b) { return ::a[a] > ::a[b]; });
    for (int i = 1; i < n; ++i) {
      if (a[vec[i - 1]] != a[vec[i]]) {
        g[find(vec[i - 1])].push_back(find(vec[i]));
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cout << f(find(i * m + j)) << ' ';
    }
    cout << '\n';
  }
  return 0;
}
