#include <bits/stdc++.h>
using namespace std;
inline int Readint() {
  int ret = 0;
  int f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f *= -1;
  } while (ch >= 0 && (ch < '0' || ch > '9'));
  while ('0' <= ch && ch <= '9') {
    ret = ret * 10 + ch - '0';
    ch = getchar();
  }
  return ret * f;
}
void open() {
  freopen("C.in", "r", stdin);
  freopen("C.out", "w", stdout);
}
void close() {
  fclose(stdin);
  fclose(stdout);
}
const int MAXN = 1010101;
int to[MAXN * 8];
int nxt[MAXN * 8];
int hd[MAXN];
int tot;
int in[MAXN];
struct node {
  int id;
  int val;
} a[MAXN], b[MAXN];
int mx = 0;
int fa[MAXN];
int rk[MAXN];
int col[MAXN];
int n, m;
inline void add(const int &x, const int &y) {
  tot++;
  to[tot] = y;
  nxt[tot] = hd[x];
  hd[x] = tot;
  in[y]++;
}
int get_fa(int p) {
  if (fa[p] == p)
    return p;
  else
    return fa[p] = get_fa(fa[p]);
}
bool cmp(node a, node b) { return a.val < b.val; }
void init() {
  n = Readint(), m = Readint();
  for (int i = 1, _END_ = n * m; i <= _END_; i++) fa[i] = i;
  int so;
  int A, B, id;
  for (int i = 1, _END_ = n; i <= _END_; i++)
    for (int j = 1, _END_ = m; j <= _END_; j++) {
      so = Readint();
      id = A = (i - 1) * m + j;
      B = (j - 1) * n + i;
      a[A].id = b[B].id = id;
      a[A].val = so;
      b[B].val = so;
    }
  for (int i = 1, _END_ = n; i <= _END_; i++)
    sort(a + 1 + (i - 1) * m, a + 1 + i * m, cmp);
  for (int i = 1, _END_ = m; i <= _END_; i++)
    sort(b + 1 + (i - 1) * n, b + 1 + i * n, cmp);
  int vv, lst, now;
  int fx, fy;
  int tot;
  for (int i = 1, _END_ = n; i <= _END_; i++) {
    tot = (i - 1) * m + 1;
    vv = a[tot].val;
    lst = tot;
    for (int j = 2, _END_ = m; j <= _END_; j++) {
      tot++;
      if (vv == a[tot].val) {
        fx = get_fa(a[lst].id);
        fy = get_fa(a[tot].id);
        if (fx != fy) {
          if (rk[fx] < rk[fy]) swap(fx, fy);
          fa[fy] = fx;
          if (rk[fx] == rk[fy]) rk[fx]++;
        }
      } else {
        lst = tot;
        vv = a[tot].val;
      }
    }
  }
  for (int i = 1, _END_ = m; i <= _END_; i++) {
    tot = (i - 1) * n + 1;
    vv = b[tot].val;
    lst = tot;
    for (int j = 2, _END_ = n; j <= _END_; j++) {
      tot++;
      if (vv == b[tot].val) {
        fx = get_fa(b[lst].id);
        fy = get_fa(b[tot].id);
        if (fx != fy) {
          if (rk[fx] < rk[fy]) swap(fx, fy);
          fa[fy] = fx;
          if (rk[fx] == rk[fy]) rk[fx]++;
        }
      } else {
        lst = tot;
        vv = b[tot].val;
      }
    }
  }
  for (int i = 1, _END_ = n; i <= _END_; i++) {
    tot = (i - 1) * m + 1;
    vv = a[tot].val;
    lst = get_fa(a[tot].id);
    for (int j = 2, _END_ = m; j <= _END_; j++) {
      tot++;
      if (vv != a[tot].val) {
        now = get_fa(a[tot].id);
        add(lst, now);
        lst = now;
        vv = a[tot].val;
      }
    }
  }
  for (int i = 1, _END_ = m; i <= _END_; i++) {
    tot = (i - 1) * n + 1;
    vv = b[tot].val;
    lst = get_fa(b[tot].id);
    for (int j = 2, _END_ = n; j <= _END_; j++) {
      tot++;
      if (vv != b[tot].val) {
        now = get_fa(b[tot].id);
        add(lst, now);
        lst = now;
        vv = b[tot].val;
      }
    }
  }
}
int que[MAXN];
void top() {
  int l = 0, r = 0;
  mx++;
  for (int i = 1, _END_ = n * m; i <= _END_; i++)
    if (fa[i] == i && (!in[i])) {
      que[r++] = i;
      col[i] = mx;
    }
  int now;
  while (l < r) {
    now = que[l++];
    for (int i = hd[now]; i; i = nxt[i]) {
      in[to[i]]--;
      if (!in[to[i]]) {
        col[to[i]] = col[now] + 1;
        que[r++] = to[i];
      }
    }
  }
}
void output() {
  int now = 0;
  for (int i = 1, _END_ = n; i <= _END_; i++) {
    for (int j = 1, _END_ = m; j <= _END_; j++) {
      now++;
      printf("%d ", col[get_fa(now)]);
    }
    printf("\n");
  }
}
int main() {
  int _ = 0;
  init();
  top();
  output();
  close();
  return 0;
}
