#include <bits/stdc++.h>
using namespace std;
int get() {
  int x = 0;
  char s = getchar();
  while (s < '0' || s > '9') s = getchar();
  while (s >= '0' && s <= '9')
    x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();
  return x;
}
int Max(const int x, const int y) {
  if (x > y) return x;
  return y;
}
const int M = 1e6 + 5;
int n, m, f[M], in[M], ans[M];
struct node {
  int x, id;
  node() {}
  node(const int X, const int I) { x = X, id = I; }
  bool operator<(const node t) const { return x < t.x; }
};
vector<node> a[M], b[M];
vector<int> G[M];
int Find(const int x) {
  if (f[x] ^ x) f[x] = Find(f[x]);
  return f[x];
}
int main() {
  n = get(), m = get();
  int id = 0;
  for (int i = 1, x; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      x = get(), ++id, f[id] = id;
      a[i].push_back(node(x, id));
      b[j].push_back(node(x, id));
    }
  for (int i = 1; i <= n; ++i) {
    sort(a[i].begin(), a[i].end());
    for (int j = 0; j < m - 1; ++j)
      if (a[i][j].x == a[i][j + 1].x)
        f[Find(a[i][j].id)] = Find(a[i][j + 1].id);
  }
  for (int i = 1; i <= m; ++i) {
    sort(b[i].begin(), b[i].end());
    for (int j = 0; j < n - 1; ++j)
      if (b[i][j].x == b[i][j + 1].x)
        f[Find(b[i][j].id)] = Find(b[i][j + 1].id);
  }
  for (int i = 1; i <= id; ++i)
    if (Find(i) == i) G[0].push_back(i), ++in[i];
  for (int i = 1, u, v; i <= n; ++i)
    for (int j = 0; j < m - 1; ++j) {
      u = Find(a[i][j].id), v = Find(a[i][j + 1].id);
      if (u ^ v) G[u].push_back(v), ++in[v];
    }
  for (int i = 1, u, v; i <= m; ++i)
    for (int j = 0; j < n - 1; ++j) {
      u = Find(b[i][j].id), v = Find(b[i][j + 1].id);
      if (u ^ v) G[u].push_back(v), ++in[v];
    }
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 0, v; i < G[x].size(); ++i) {
      v = G[x][i];
      ans[v] = Max(ans[v], ans[x] + 1);
      if (!(--in[v])) q.push(v);
    }
  }
  id = 0;
  for (int i = 1; i <= n; ++i, putchar('\n'))
    for (int j = 1; j <= m; ++j) printf("%d ", ans[Find(++id)]);
  return 0;
}
