#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1000003;
int n, m, a[MaxN];
pair<int, int> t[MaxN];
vector<int> e[MaxN], g[MaxN];
int fa[MaxN], rk[MaxN], deg[MaxN], mn[MaxN];
int getfa(const int& x) { return (fa[x] == x) ? x : (fa[x] = getfa(fa[x])); }
inline void uni(int u, int v) {
  u = getfa(u), v = getfa(v);
  if (u == v) return;
  if (rk[u] < rk[v]) swap(u, v);
  fa[v] = u;
  if (rk[u] == rk[v]) rk[u]++;
}
inline bool same(int u, int v) { return getfa(u) == getfa(v); }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n * m; ++i) scanf("%d", a + i);
  for (int i = 1; i <= n * m; ++i) fa[i] = i, rk[i] = 1;
  for (int i = 1; i <= n; ++i) {
    int* p = a + ((i - 1) * m);
    for (int j = 1; j <= m; ++j) t[j].first = p[j], t[j].second = p + j - a;
    sort(t + 1, t + m + 1);
    for (int j = 1; j < m; ++j) {
      if (t[j].first != t[j + 1].first)
        e[t[j].second].push_back(t[j + 1].second);
      else
        uni(t[j].second, t[j + 1].second);
    }
  }
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= n; ++j)
      t[j].second = (j - 1) * m + i, t[j].first = a[t[j].second];
    sort(t + 1, t + n + 1);
    for (int j = 1; j < n; ++j) {
      if (t[j].first != t[j + 1].first)
        e[t[j].second].push_back(t[j + 1].second);
      else
        uni(t[j].second, t[j + 1].second);
    }
  }
  for (int i = 1; i <= n * m; ++i)
    for (vector<int>::iterator j = e[i].begin(); j != e[i].end(); ++j) {
      g[getfa(i)].push_back(getfa(*j));
      deg[getfa(*j)]++;
    }
  deque<int> q;
  for (int i = 1; i <= n * m; ++i)
    if (getfa(i) == i && deg[i] == 0) q.push_back(i), mn[i] = 1;
  while (!q.empty()) {
    int t = q.front();
    q.pop_front();
    for (int i : g[t]) {
      deg[i]--;
      mn[i] = max(mn[i], mn[t] + 1);
      if (deg[i] == 0) q.push_back(i);
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) printf("%d ", mn[getfa((i - 1) * m + j)]);
    putchar('\n');
  }
  return 0;
}
