#include <bits/stdc++.h>
using namespace std;
const int MAXN = 8000005;
struct EDGE {
  int to, next;
  EDGE() {}
  EDGE(int to, int next) : to(to), next(next) {}
} edge[MAXN];
int head[2000005], edgecnt;
void init() {
  memset(head, -1, sizeof(head));
  edgecnt = 0;
}
void add(int s, int t) {
  edge[edgecnt] = EDGE(t, head[s]);
  head[s] = edgecnt++;
}
int fa[2000005];
int findfa(int x) {
  if (x != fa[x]) return fa[x] = findfa(fa[x]);
  return fa[x];
}
void un(int a, int b) {
  int x = findfa(a);
  int y = findfa(b);
  if (x != y) fa[x] = y;
}
int dp[2000005];
struct point {
  int x, y, val;
  point() {}
  point(int x, int y, int val) : x(x), y(y), val(val) {}
  bool operator<(const point &b) const {
    if (val == b.val) {
      if (x == b.x) return y < b.y;
      return x < b.x;
    }
    return val < b.val;
  }
} p[2000005];
int n, m;
int getid(int x, int y) { return x * m + y; }
bool vis[2000005];
void dfs(int u) {
  vis[u] = 1;
  dp[u] = 1;
  for (int i = head[u]; ~i; i = edge[i].next) {
    int v = findfa(edge[i].to);
    if (!vis[v]) dfs(v);
    dp[u] = max(dp[u], dp[v] + 1);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i <= n * m; i++) fa[i] = i;
  vector<vector<int> > v(n, vector<int>(m, 0));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &v[i][j]);
  init();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) p[j] = point(i, j, v[i][j]);
    sort(p, p + m);
    for (int j = 1; j < m; j++)
      if (p[j - 1].val == p[j].val)
        un(getid(p[j].x, p[j].y), getid(p[j - 1].x, p[j - 1].y));
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) p[i] = point(i, j, v[i][j]);
    sort(p, p + n);
    for (int i = 1; i < n; i++)
      if ((p[i - 1].val == p[i].val))
        un(getid(p[i].x, p[i].y), getid(p[i - 1].x, p[i - 1].y));
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) p[j] = point(i, j, v[i][j]);
    sort(p, p + m);
    for (int j = 1; j < m; j++)
      if (p[j - 1].val != p[j].val)
        add(findfa(getid(p[j].x, p[j].y)),
            findfa(getid(p[j - 1].x, p[j - 1].y)));
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) p[i] = point(i, j, v[i][j]);
    sort(p, p + n);
    for (int i = 1; i < n; i++)
      if ((p[i - 1].val != p[i].val))
        add(findfa(getid(p[i].x, p[i].y)),
            findfa(getid(p[i - 1].x, p[i - 1].y)));
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (!vis[findfa(getid(i, j))]) dfs(findfa(getid(i, j)));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) printf("%d ", dp[findfa(getid(i, j))]);
    printf("\n");
  }
  return 0;
}
