#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int getint() {
  int r = 0, k = 1;
  char c = getchar();
  for (; '0' > c || c > '9'; c = getchar())
    if (c == '-') k = -1;
  for (; '0' <= c && c <= '9'; c = getchar()) r = r * 10 - '0' + c;
  return r * k;
}
const int maxnm = 1000005;
int n, m;
struct datatype {
  int a[maxnm];
  int b[maxnm];
  int get(int h, int l) { return a[(h - 1) * m + l]; }
  int getb(int h, int l) { return b[(h - 1) * m + l]; }
  int id(int h, int l) { return (h - 1) * m + l; }
} A;
int tot = 0;
int f[maxnm];
int q[maxnm];
int col[maxnm], coll[maxnm], rd[maxnm], h[maxnm];
struct edge_type {
  int to, next;
} edge[maxnm * 5];
int cnte = 1;
void ins(int u, int v) {
  edge[++cnte].to = v;
  edge[cnte].next = h[u];
  h[u] = cnte;
  ++rd[v];
}
void tppx() {
  int head = 0, tail = 0;
  for (int i = 1; i <= tot; ++i)
    if (rd[i] == 0) q[tail++] = i, col[i] = 1;
  int now;
  while (head < tail) {
    now = q[head++];
    for (int i = h[now]; i; i = edge[i].next) {
      rd[edge[i].to]--;
      if (rd[edge[i].to] == 0) {
        q[tail++] = edge[i].to;
        col[edge[i].to] = col[now] + 1;
      }
    }
  }
}
int find(int x) { return f[x] == x ? x : find(f[x]); }
struct my_type {
  int val, id;
  my_type() {
    val = 0;
    id = 0;
  }
  my_type(int v, int d) {
    val = v;
    id = d;
  }
};
bool operator<(my_type a, my_type b) { return a.val < b.val; }
priority_queue<my_type> pq;
bool allsame = true;
int main() {
  n = getint();
  m = getint();
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      A.a[++tot] = getint();
      f[tot] = tot;
    }
  my_type tmp, lst;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j)
      pq.push(my_type(A.get(i, j), find(A.id(i, j))));
    tmp = pq.top();
    pq.pop();
    while (!pq.empty()) {
      lst = tmp;
      tmp = pq.top();
      pq.pop();
      if (tmp.val == lst.val) f[find(tmp.id)] = find(lst.id);
    }
  }
  for (int j = 1; j <= m; ++j) {
    for (int i = 1; i <= n; ++i)
      pq.push(my_type(A.get(i, j), find(A.id(i, j))));
    tmp = pq.top();
    pq.pop();
    while (!pq.empty()) {
      lst = tmp;
      tmp = pq.top();
      pq.pop();
      if (tmp.val == lst.val) f[find(tmp.id)] = find(lst.id);
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j)
      pq.push(my_type(A.get(i, j), find(A.id(i, j))));
    tmp = pq.top();
    pq.pop();
    while (!pq.empty()) {
      lst = tmp;
      tmp = pq.top();
      pq.pop();
      if (lst.val == tmp.val) continue;
      ins(find(tmp.id), find(lst.id));
    }
  }
  for (int j = 1; j <= m; ++j) {
    for (int i = 1; i <= n; ++i)
      pq.push(my_type(A.get(i, j), find(A.id(i, j))));
    tmp = pq.top();
    pq.pop();
    while (!pq.empty()) {
      lst = tmp;
      tmp = pq.top();
      pq.pop();
      if (lst.val == tmp.val) continue;
      ins(find(tmp.id), find(lst.id));
    }
  }
  tppx();
  for (int i = 1; i <= tot; ++i) A.b[i] = col[find(i)];
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) printf("%d ", A.getb(i, j));
    printf("\n");
  }
}
