#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int SZ = 1e6 + 10;
vector<int> g[SZ];
int n, m, ans[SZ], p[SZ];
int get(int v) {
  if (p[v] != v) p[v] = get(p[v]);
  return p[v];
}
int join(int u, int v) { p[get(u)] = get(v); }
int f(int i, int j) { return i * m + j; }
int solve(int v) {
  if (ans[v]) return ans[v];
  int mx = 0;
  for (int u : g[v]) mx = max(mx, solve(u));
  ans[v] = mx + 1;
  return ans[v];
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  vector<vector<int>> a(n, vector<int>(m));
  vector<vector<tuple<int, int, int>>> r(n), c(m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < SZ; i++) p[i] = i;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) r[i].push_back(make_tuple(a[i][j], i, j));
    sort(r[i].begin(), r[i].end());
    for (int j = 0; j < m - 1; j++)
      if (get<0>(r[i][j]) == get<0>(r[i][j + 1]))
        join(f(get<1>(r[i][j]), get<2>(r[i][j])),
             f(get<1>(r[i][j + 1]), get<2>(r[i][j + 1])));
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) c[j].push_back(make_tuple(a[i][j], i, j));
    sort(c[j].begin(), c[j].end());
    for (int i = 0; i < n - 1; i++)
      if (get<0>(c[j][i]) == get<0>(c[j][i + 1]))
        join(f(get<1>(c[j][i]), get<2>(c[j][i])),
             f(get<1>(c[j][i + 1]), get<2>(c[j][i + 1])));
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      auto it =
          lower_bound(r[i].begin(), r[i].end(), make_tuple(a[i][j], 0, 0));
      if (it != r[i].begin()) {
        it--;
        g[get(f(i, j))].push_back(get(f(get<1>(*it), get<2>(*it))));
      }
      it = lower_bound(c[j].begin(), c[j].end(), make_tuple(a[i][j], 0, 0));
      if (it != c[j].begin()) {
        it--;
        g[get(f(i, j))].push_back(get(f(get<1>(*it), get<2>(*it))));
      }
    }
  }
  for (int i = 0; i < SZ; i++) solve(i);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << ans[get(f(i, j))] << ' ';
    cout << endl;
  }
  return 0;
}
