#include <bits/stdc++.h>
using namespace std;
void chkmin(int &a, int b) {
  if (a > b) a = b;
}
int n, m;
int a[1000005], b[1000005], G;
vector<int> v[1000005], w[1000005];
int idx(int i, int j) { return m * i + j; }
bool cmp(int x, int y) { return b[x] < b[y]; }
int dt[1000005], d[1000005], low[1000005], q[1000005], qs, cs, c[1000005],
    id[1000005];
bool in[1000005];
void dfs(int k) {
  dt[k] = low[k] = ++G;
  in[k] = 1;
  q[qs++] = k;
  for (auto x : v[k]) {
    if (!dt[x]) {
      dfs(x);
      chkmin(low[x], low[k]);
    } else if (in[x])
      chkmin(low[k], dt[x]);
  }
  if (low[k] == dt[k]) {
    cs++;
    while (q[--qs] != k) c[q[qs]] = cs, in[q[qs]] = 0;
    c[k] = cs;
    in[k] = 0;
  }
  return;
}
int func(int k) {
  if (d[k]) return d[k];
  d[k] = 1;
  for (auto x : w[k]) d[k] = max(d[k], func(x) + 1);
  return d[k];
}
int main() {
  scanf("%d %d", &n, &m);
  int up = 0, x, y;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      scanf("%d", &x);
      a[up++] = x;
    }
  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++) {
      x = idx(i, id[j]), y = idx(i, id[j + 1]);
      v[y].push_back(x);
      if (a[x] == a[y]) v[x].push_back(y);
    }
  }
  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++) {
      x = idx(id[i], j), y = idx(id[i + 1], j);
      v[y].push_back(x);
      if (a[x] == a[y]) v[x].push_back(y);
    }
  }
  for (int i = 0; i < up; i++)
    if (!dt[i]) dfs(i);
  for (int i = 0; i < up; i++)
    for (auto x : v[i])
      if (c[x] != c[i]) w[c[i]].push_back(c[x]);
  for (int i = 1; i <= cs; i++) func(i);
  x = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      printf("%d ", d[c[x]]);
      x++;
    }
    puts("");
  }
  return 0;
}
