#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, m, k;
int a[N];
int fa[N];
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
int b[N], pos[N];
bool comp(int x, int y) { return b[x] < b[y]; }
void merge(int u, int v) {
  int fu = find(u), fv = find(v);
  if (fu == fv) return;
  fa[fu] = fv;
}
struct Edge {
  int v;
  Edge *next;
  Edge() {}
  Edge(int v, Edge *next) : v(v), next(next) {}
} pool[N << 1], *pis = pool, *fst[N];
int in[N];
void Add(int u, int v) {
  *pis = Edge(v, fst[u]);
  fst[u] = pis++;
  in[v]++;
}
int q[N], head, tail;
int d[N];
void BFS() {
  tail = head = 0;
  for (int i = 1; i <= k; i++) {
    if (find(i) == i && !in[i]) {
      q[tail++] = i;
      d[i] = 1;
    }
  }
  while (head < tail) {
    int u = q[head++];
    for (Edge *i = fst[u]; i; i = i->next) {
      int v = i->v;
      if (--in[v]) continue;
      d[v] = d[u] + 1;
      q[tail++] = v;
    }
  }
}
void Init() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", a + (++k));
    }
  }
  for (int i = 1; i <= k; i++) fa[i] = i;
  for (int i = 1, t = 0; i <= n; i++, t += m) {
    for (int j = 1; j <= m; j++) b[j] = a[t + j], pos[j] = j;
    sort(pos + 1, pos + m + 1, comp);
    for (int j = 2; j <= m; j++) {
      if (b[pos[j - 1]] == b[pos[j]]) merge(t + pos[j - 1], t + pos[j]);
    }
  }
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++) b[i] = a[(i - 1) * m + j], pos[i] = i;
    sort(pos + 1, pos + n + 1, comp);
    for (int i = 2; i <= n; i++) {
      if (b[pos[i - 1]] == b[pos[i]])
        merge((pos[i - 1] - 1) * m + j, (pos[i] - 1) * m + j);
    }
  }
  for (int i = 1, t = 0; i <= n; i++, t += m) {
    for (int j = 1; j <= m; j++) b[j] = a[t + j], pos[j] = j;
    sort(pos + 1, pos + m + 1, comp);
    for (int j = 2; j <= m; j++) {
      if (b[pos[j - 1]] != b[pos[j]]) {
        Add(find(t + pos[j - 1]), find(t + pos[j]));
      }
    }
  }
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++) b[i] = a[(i - 1) * m + j], pos[i] = i;
    sort(pos + 1, pos + n + 1, comp);
    for (int i = 2; i <= n; i++) {
      if (b[pos[i - 1]] != b[pos[i]]) {
        Add(find((pos[i - 1] - 1) * m + j), find((pos[i] - 1) * m + j));
      }
    }
  }
}
int main() {
  Init();
  BFS();
  for (int i = 1, t = 0; i <= n; i++, t += m) {
    for (int j = 1; j <= m; j++) {
      printf("%d%c", d[find(t + j)], j == m ? '\n' : ' ');
    }
  }
  return 0;
}
