#include <bits/stdc++.h>
char _bf[1048576];
char *__p1 = _bf, *__p2 = _bf;
template <class T>
void PRT(const T _) {
  if (_ < 0) {
    putchar(45), PRT(-_);
    return;
  }
  if (_ >= 10) PRT(_ / 10);
  putchar(_ % 10 + 48);
}
template <class T>
void UPRT(const T _) {
  if (_ >= 10) UPRT(_ / 10);
  putchar(_ % 10 + 48);
}
constexpr int MN(1e6 + 7), MV(MN), ME(MV << 1);
struct Elem {
  int val;
  int r, c, pos;
  int id;
} a[MN];
struct Iter {
  Elem *ptr;
  inline Iter &operator=(Elem *ptr) {
    this->ptr = ptr;
    return *this;
  }
  inline Elem *operator->(void) { return ptr; }
  inline bool operator<(const Iter o) const { return ptr->val < o.ptr->val; }
} iter[MN];
namespace UF {
int uf[MV];
int find(const int x) { return uf[x] == x ? x : uf[x] = find(uf[x]); }
inline void merge(const int x, const int y) { uf[x] = y; }
};  // namespace UF
int last_r_pos[MN];
int last_c_pos[MN];
int main() {
  char *_p1 = __p1, *_p2 = __p2;
  int R, C;
  {
    char _c = (_p1 == _p2 && (_p2 = (_p1 = _bf) + fread(_bf, 1, 1048576, stdin),
                              _p1 == _p2)
                   ? EOF
                   : *_p1++),
         _v = 1;
    for (R = 0; _c < 48 || _c > 57;
         _c = (_p1 == _p2 && (_p2 = (_p1 = _bf) + fread(_bf, 1, 1048576, stdin),
                             _p1 == _p2)
                   ? EOF
                   : *_p1++))
      if (_c == 45) _v = -1;
    for (; _c >= 48 && _c <= 57;
         R = (R << 1) + (R << 3) + _c - 48,
         _c = (_p1 == _p2 && (_p2 = (_p1 = _bf) + fread(_bf, 1, 1048576, stdin),
                             _p1 == _p2)
                   ? EOF
                   : *_p1++))
      ;
    if (_v == -1) R = -R;
  }
  {
    char _c = (_p1 == _p2 && (_p2 = (_p1 = _bf) + fread(_bf, 1, 1048576, stdin),
                              _p1 == _p2)
                   ? EOF
                   : *_p1++),
         _v = 1;
    for (C = 0; _c < 48 || _c > 57;
         _c = (_p1 == _p2 && (_p2 = (_p1 = _bf) + fread(_bf, 1, 1048576, stdin),
                             _p1 == _p2)
                   ? EOF
                   : *_p1++))
      if (_c == 45) _v = -1;
    for (; _c >= 48 && _c <= 57;
         C = (C << 1) + (C << 3) + _c - 48,
         _c = (_p1 == _p2 && (_p2 = (_p1 = _bf) + fread(_bf, 1, 1048576, stdin),
                             _p1 == _p2)
                   ? EOF
                   : *_p1++))
      ;
    if (_v == -1) C = -C;
  }
  int tot = 0;
  for (auto r = 1; r <= R; ++r) {
    for (auto c = 1; c <= C; ++c) {
      ++tot;
      UF::uf[tot] = tot;
      {
        char _c = (_p1 == _p2 &&
                           (_p2 = (_p1 = _bf) + fread(_bf, 1, 1048576, stdin),
                            _p1 == _p2)
                       ? EOF
                       : *_p1++),
             _v = 1;
        for (a[tot].val = 0; _c < 48 || _c > 57;
             _c = (_p1 == _p2 &&
                           (_p2 = (_p1 = _bf) + fread(_bf, 1, 1048576, stdin),
                           _p1 == _p2)
                       ? EOF
                       : *_p1++))
          if (_c == 45) _v = -1;
        for (; _c >= 48 && _c <= 57;
             a[tot].val = (a[tot].val << 1) + (a[tot].val << 3) + _c - 48,
             _c = (_p1 == _p2 &&
                           (_p2 = (_p1 = _bf) + fread(_bf, 1, 1048576, stdin),
                           _p1 == _p2)
                       ? EOF
                       : *_p1++))
          ;
        if (_v == -1) a[tot].val = -a[tot].val;
      }
      a[tot].r = r, a[tot].c = c, a[tot].pos = tot, iter[tot] = a + tot;
    }
  }
  std::sort(iter + 1, iter + tot + 1);
  int id1, id2;
  Elem *p;
  for (auto i = 1; i <= tot; ++i) {
    p = iter[i].ptr;
    const int last_r_p = UF::find(last_r_pos[p->c]);
    const int last_c_p = UF::find(last_c_pos[p->r]);
    if (p->val == a[last_r_p].val) UF::merge(last_r_p, p->pos);
    if (p->val == a[last_c_p].val) UF::merge(last_c_p, p->pos);
    id1 = a[last_r_p].id + (p->val > a[last_r_p].val);
    id2 = a[last_c_p].id + (p->val > a[last_c_p].val);
    p->id = ((id1) > (id2) ? (id1) : (id2));
    last_r_pos[p->c] = last_c_pos[p->r] = p->pos;
  }
  for (int i = 1; i <= tot; putchar(10))
    for (int c = 0; c < C; ++c, ++i) UPRT(a[UF::find(i)].id), putchar(32);
  return 0;
}
