#include <bits/stdc++.h>
using namespace std;
template <class T>
void chkmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
void chkmin(T &a, T b) {
  if (a > b) a = b;
}
const int inf = 0x3f3f3f3f;
const long long linf = 2e18 + 100;
const double eps = 1e-7;
int n, m;
int a[1000005], b[1000005], G;
vector<int> v[1000005], rv[1000005];
int idx(int i, int j) { return m * i + j; }
bool cmp(int first, int second) { return b[first] < b[second]; }
int dt[1000005], fs[1000005], q[1000005], qs, cs, c[1000005], id[1000005];
bool vis[1000005];
void dfs(int k) {
  dt[k] = ++G;
  for (auto first : v[k]) {
    if (!dt[first])
      dfs(first);
    else
      continue;
  }
  fs[k] = ++G;
  q[qs++] = k;
  return;
}
void efs(int k) {
  vis[k] = 1;
  c[k] = cs;
  for (auto first : rv[k]) {
    if (vis[first]) continue;
    efs(first);
  }
  return;
}
vector<int> w[1000005];
int d[1000005];
int func(int k) {
  if (d[k]) return d[k];
  d[k] = 1;
  for (auto first : w[k]) {
    d[k] = max(d[k], func(first) + 1);
  }
  return d[k];
}
int main() {
  scanf("%d %d", &n, &m);
  int up = 0, first, second;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      scanf("%d", &first);
      a[up++] = first;
    }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) id[j] = j, b[j] = a[idx(i, j)];
    sort(id, id + m, cmp);
    for (int j = 0; j < m - 1; j++) {
      first = idx(i, id[j]), second = idx(i, id[j + 1]);
      v[second].push_back(first);
      rv[first].push_back(second);
      if (a[first] == a[second])
        v[first].push_back(second), rv[second].push_back(first);
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) id[i] = i, b[i] = a[idx(i, j)];
    sort(id, id + n, cmp);
    for (int i = 0; i < n - 1; i++) {
      first = idx(id[i], j), second = idx(id[i + 1], j);
      v[second].push_back(first);
      rv[first].push_back(second);
      if (a[first] == a[second])
        v[first].push_back(second), rv[second].push_back(first);
    }
  }
  for (int i = 0; i < up; i++)
    if (!dt[i]) dfs(i);
  for (int i = qs - 1; i >= 0; i--)
    if (!vis[q[i]]) {
      cs++;
      efs(q[i]);
    }
  for (int i = 0; i < up; i++) {
    for (auto first : v[i]) {
      if (c[first] != c[i]) {
        w[c[i]].push_back(c[first]);
      }
    }
  }
  for (int i = 1; i <= cs; i++) func(i);
  first = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      printf("%d", d[c[first]]);
      if (j == m - 1)
        puts("");
      else
        putchar(' ');
      first++;
    }
  }
  return 0;
}
