#include <bits/stdc++.h>
using namespace std;
template <typename T, typename S>
inline bool upmin(T& a, const S& b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T, typename S>
inline bool upmax(T& a, const S& b) {
  return a < b ? a = b, 1 : 0;
}
template <typename N, typename PN>
inline N flo(N a, PN b) {
  return a >= 0 ? a / b : -((-a - 1) / b) - 1;
}
template <typename N, typename PN>
inline N cei(N a, PN b) {
  return a > 0 ? (a - 1) / b + 1 : -(-a / b);
}
template <typename N>
N gcd(N a, N b) {
  return b ? gcd(b, a % b) : a;
}
inline void gn(long long& x) {
  int sg = 1;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  c == '-' ? (sg = -1, x = 0) : (x = c - '0');
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= sg;
}
inline void gn(int& x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(unsigned long long& x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(double& x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline void gn(long double& x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline long long sqr(long long a) { return a * a; }
inline double sqrf(double a) { return a * a; }
int inf = 0x3f3f3f3f;
double eps = 1e-6;
int mo = 1000000007;
int qp(int a, long long b) {
  int n = 1;
  do {
    if (b & 1) n = 1ll * n * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return n;
}
int n, m;
int a[1111111];
int fa[1111111];
int gf(int x) { return x == fa[x] ? x : fa[x] = gf(fa[x]); }
struct edge {
  int v, next;
} e[1111111 * 2];
int g[1111111];
int etot = 0;
int deg[1111111];
void ae(int u, int v) {
  e[etot].v = v;
  e[etot].next = g[u];
  g[u] = etot++;
  deg[v]++;
}
int ord[1111111];
int ci, cj;
int cmpj(int j1z, int j2) {
  return a[(((ci)-1) * (m) + (j1z))] < a[(((ci)-1) * (m) + (j2))];
}
int cmpi(int i1, int i2) {
  return a[(((i1)-1) * (m) + (cj))] < a[(((i2)-1) * (m) + (cj))];
}
void un(int a, int b) {
  a = gf(a);
  b = gf(b);
  if (a != b) fa[a] = b;
}
int seq[1111111];
int qu[1111111];
int le[1111111];
void bfs() {
  int p = 0, q = 0;
  for (int i = (1), _ed = (n * m + 1); i < _ed; i++)
    if (gf(i) == i && deg[i] == 0) qu[q++] = i;
  while (p != q) {
    int u = qu[p++];
    for (int i = g[u]; ~i; i = e[i].next) {
      if ((--deg[e[i].v]) == 0) {
        qu[q++] = e[i].v;
      }
    }
  }
  for (int i = 0; i <= q - 1; i++) {
    int u = qu[i];
    for (int i = g[u]; ~i; i = e[i].next) upmax(le[e[i].v], le[u] + 1);
  }
}
int main() {
  memset((g), (-1), sizeof(g));
  gn(n);
  gn(m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      gn(a[(((i)-1) * (m) + (j))]);
      fa[(((i)-1) * (m) + (j))] = (((i)-1) * (m) + (j));
    }
  for (int i = (1), _ed = (n + 1); i < _ed; i++) {
    for (int j = (1), _ed = (m + 1); j < _ed; j++) ord[j] = j;
    ci = i;
    sort(ord + 1, ord + 1 + m, cmpj);
    for (int j = (1), _ed = (m); j < _ed; j++) {
      if (a[(((i)-1) * (m) + (ord[j]))] == a[(((i)-1) * (m) + (ord[j + 1]))]) {
        un((((i)-1) * (m) + (ord[j])), (((i)-1) * (m) + (ord[j + 1])));
      }
    }
  }
  for (int j = (1), _ed = (m + 1); j < _ed; j++) {
    for (int i = (1), _ed = (n + 1); i < _ed; i++) ord[i] = i;
    cj = j;
    sort(ord + 1, ord + 1 + n, cmpi);
    for (int i = (1), _ed = (n); i < _ed; i++) {
      if (a[(((ord[i]) - 1) * (m) + (j))] ==
          a[(((ord[i + 1]) - 1) * (m) + (j))]) {
        un((((ord[i]) - 1) * (m) + (j)), (((ord[i + 1]) - 1) * (m) + (j)));
      }
    }
  }
  for (int i = (1), _ed = (n + 1); i < _ed; i++) {
    for (int j = (1), _ed = (m + 1); j < _ed; j++) ord[j] = j;
    ci = i;
    sort(ord + 1, ord + 1 + m, cmpj);
    for (int j = (1), _ed = (m); j < _ed; j++) {
      if (a[(((i)-1) * (m) + (ord[j]))] < a[(((i)-1) * (m) + (ord[j + 1]))]) {
        ae(gf((((i)-1) * (m) + (ord[j]))), gf((((i)-1) * (m) + (ord[j + 1]))));
      }
    }
  }
  for (int j = (1), _ed = (m + 1); j < _ed; j++) {
    for (int i = (1), _ed = (n + 1); i < _ed; i++) ord[i] = i;
    cj = j;
    sort(ord + 1, ord + 1 + n, cmpi);
    for (int i = (1), _ed = (n); i < _ed; i++) {
      if (a[(((ord[i]) - 1) * (m) + (j))] <
          a[(((ord[i + 1]) - 1) * (m) + (j))]) {
        ae(gf((((ord[i]) - 1) * (m) + (j))),
           gf((((ord[i + 1]) - 1) * (m) + (j))));
      }
    }
  }
  bfs();
  for (int i = (1), _ed = (n + 1); i < _ed; i++) {
    for (int j = (1), _ed = (m + 1); j < _ed; j++)
      printf("%d ", le[gf((((i)-1) * (m) + (j)))] + 1);
    putchar('\n');
  }
  return 0;
}
