#include <bits/stdc++.h>
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
inline bool isDigit(char x) { return x >= '0' && x <= '9'; }
inline int read() {
  static char ch;
  bool sgn = false;
  while (!isDigit(ch = getchar()))
    if (ch == '-') sgn = true;
  int ret = ch - 48;
  while (isDigit(ch = getchar())) ret = ret * 10 + ch - 48;
  return (sgn ? -ret : ret);
}
const int N = 1e6 + 5;
const int INF = 0x7FFFFFFF;
int n, m, a[N], anc[N];
std::vector<int> row[N], col[N];
int ecnt, adj[N], nxt[N * 2], go[N * 2], du[N];
int ans[N], qn, que[N];
inline void addEdge(const int &u, const int &v) {
  nxt[++ecnt] = adj[u], adj[u] = ecnt, go[ecnt] = v;
  ++du[v];
}
inline bool cmp(const int &x, const int &y) { return a[x] < a[y]; }
inline int ufs(const int &x) {
  if (anc[x] == x) return x;
  return anc[x] = ufs(anc[x]);
}
int main() {
  n = read(), m = read();
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int l = i * m + j;
      a[l] = read();
      row[i].push_back(l);
      col[j].push_back(l);
    }
  }
  int nm = n * m;
  for (int i = 0; i < nm; ++i) anc[i] = i;
  for (int i = 0; i < n; ++i) {
    std::sort(row[i].begin(), row[i].end(), cmp);
    for (int j = 1; j < m; ++j) {
      if (a[row[i][j]] == a[row[i][j - 1]]) {
        int fx = ufs(row[i][j]), fy = ufs(row[i][j - 1]);
        if (fx != fy) anc[fy] = fx;
      }
    }
  }
  for (int j = 0; j < m; ++j) {
    std::sort(col[j].begin(), col[j].end(), cmp);
    for (int i = 1; i < n; ++i) {
      if (a[col[j][i]] == a[col[j][i - 1]]) {
        int fx = ufs(col[j][i]), fy = ufs(col[j][i - 1]);
        if (fx != fy) anc[fy] = fx;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j < m; ++j) {
      if (a[row[i][j]] != a[row[i][j - 1]]) {
        int fx = ufs(row[i][j]), fy = ufs(row[i][j - 1]);
        addEdge(fy, fx);
      }
    }
  }
  for (int j = 0; j < m; ++j) {
    for (int i = 1; i < n; ++i) {
      if (a[col[j][i]] != a[col[j][i - 1]]) {
        int fx = ufs(col[j][i]), fy = ufs(col[j][i - 1]);
        addEdge(fy, fx);
      }
    }
  }
  for (int i = 0; i < nm; ++i)
    if (ufs(i) == i && du[i] == 0) que[++qn] = i, ans[i] = 1;
  for (int ql = 1; ql <= qn; ++ql) {
    int u = que[ql];
    for (int e = adj[u], v; v = go[e], e; e = nxt[e]) {
      if (!--du[v]) que[++qn] = v, ans[v] = ans[u] + 1;
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      printf("%d ", ans[ufs(i * m + j)]);
    }
    printf("\n");
  }
  return 0;
}
