#include <bits/stdc++.h>
using namespace std;
char getc() {
  static char *S, *T, buf[65536];
  if (S == T) {
    T = (S = buf) + fread(buf, 1, 65536, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
int read() {
  static char ch;
  static int D;
  while (!isdigit(ch = getc()))
    ;
  for (D = ch - '0'; isdigit(ch = getc());) D = D * 10 + ch - '0';
  return D;
}
int n, m;
int ind[2000005], st[2000005], id[2000005], dis[2000005], fa[2000005];
queue<int> q;
inline int pos(int x, int y) { return (x - 1) * m + y; }
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
vector<int> v[1000005];
struct edge {
  int to, next;
} e[4000005];
int h[2000005], tp;
void ae(int u, int v) {
  u = find(u);
  v = find(v);
  if (u == v) return;
  e[++tp].to = v;
  e[tp].next = h[u];
  ind[v]++;
  h[u] = tp;
}
bool cmp(int a, int b) { return st[a] < st[b]; }
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) {
    v[i].push_back(0);
    for (int k, j = 1; j <= m; j++) v[i].push_back(read());
  }
  for (int i = 1; i <= n * m; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) id[i] = i;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) st[j] = v[i][j];
    sort(id + 1, id + m + 1, cmp);
    for (int j = 1; j < m; j++)
      if (st[id[j + 1]] == st[id[j]])
        fa[find(pos(i, id[j + 1]))] = find(pos(i, id[j]));
  }
  for (int i = 1; i <= n; i++) id[i] = i;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) st[j] = v[j][i];
    sort(id + 1, id + n + 1, cmp);
    for (int j = 1; j < n; j++)
      if (st[id[j + 1]] == st[id[j]])
        fa[find(pos(id[j + 1], i))] = find(pos(id[j], i));
  }
  for (int i = 1; i <= m; i++) id[i] = i;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) st[j] = v[i][j];
    sort(id + 1, id + m + 1, cmp);
    for (int j = 1; j < m; j++)
      if (st[id[j + 1]] != st[id[j]]) ae(pos(i, id[j]), pos(i, id[j + 1]));
  }
  for (int i = 1; i <= n; i++) id[i] = i;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) st[j] = v[j][i];
    sort(id + 1, id + n + 1, cmp);
    for (int j = 1; j < n; j++)
      if (st[id[j + 1]] != st[id[j]]) ae(pos(id[j], i), pos(id[j + 1], i));
  }
  for (int i = 1; i <= n * m; i++)
    if (find(i) == i && !ind[i]) q.push(i), dis[i] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int v, i = h[u]; i; i = e[i].next) {
      if (dis[v = e[i].to] < dis[u] + 1) dis[v] = dis[u] + 1;
      ind[v]--;
      if (!ind[v]) q.push(v);
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) printf("%d ", dis[fa[pos(i, j)]]);
    puts("");
  }
}
