#include <bits/stdc++.h>
using namespace std;
namespace FGF {
int n, m;
int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') w = -w;
    ch = getchar();
  }
  while (isdigit(ch)) {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * w;
}
const int M = 1e6 + 5, N = 1e3 + 5;
int id, fa[M], dis[M], ru[M], cnt, head[M];
struct Node {
  int val, id;
};
vector<Node> a[M], b[M];
bool cmp(const Node &x, const Node &y) { return x.val < y.val; }
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
struct edg {
  int to, nxt;
} e[M << 3];
queue<int> q;
void add(int u, int v) {
  cnt++;
  e[cnt].to = v;
  e[cnt].nxt = head[u];
  head[u] = cnt;
  ru[v]++;
}
void work() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      id++;
      fa[id] = id;
      Node tmp;
      tmp.val = read(), tmp.id = id;
      a[i].push_back(tmp), b[j].push_back(tmp);
    }
  for (int i = 1; i <= n; i++) {
    sort(a[i].begin(), a[i].end(), cmp);
    for (int j = 1; j < m; j++)
      if (a[i][j].val == a[i][j - 1].val)
        fa[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(), cmp);
    for (int j = 1; j < n; j++)
      if (b[i][j].val == b[i][j - 1].val)
        fa[find(b[i][j].id)] = find(b[i][j - 1].id);
  }
  for (int i = 1; i <= id; i++)
    if (fa[i] == i) add(n * m + 1, i);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j < m; j++)
      if (a[i][j].val != a[i][j - 1].val)
        add(find(a[i][j - 1].id), find(a[i][j].id));
  for (int i = 1; i <= m; i++)
    for (int j = 1; j < n; j++)
      if (b[i][j].val != b[i][j - 1].val)
        add(find(b[i][j - 1].id), find(b[i][j].id));
  q.push(n * m + 1);
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i; i = e[i].nxt) {
      int v = e[i].to;
      ru[v]--;
      if (ru[v] == 0) q.push(v);
      dis[v] = max(dis[v], dis[u] + 1);
    }
  }
  int id = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++) printf("%d ", dis[find(++id)]);
    puts(" ");
  }
}
}  // namespace FGF
int main() {
  FGF::work();
  return 0;
}
