#include <bits/stdc++.h>
using namespace std;
vector<int> h[1000010], l[1000010];
int hs[1000010], ls[1000010], f[1000010], ans[1000010];
int n, m, x;
struct node {
  int x, y, data, id;
  node() {}
  node(int _x, int _y, int d, int _id) {
    x = _x;
    y = _y;
    data = d, id = _id;
  }
} p[1000010], rec[1000010];
bool cmpx(node a, node b) {
  if (a.data == b.data) return a.x < b.x;
  return a.data < b.data;
}
bool cmpy(node a, node b) {
  if (a.data == b.data) return a.y < b.y;
  return a.data < b.data;
}
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%d", &x);
      p[(i - 1) * m + j] = rec[(i - 1) * m + j] =
          node(i, j, x, (i - 1) * m + j);
    }
  for (int i = 1; i <= n * m; i++) f[i] = i;
  sort(p + 1, p + 1 + n * m, cmpx);
  for (int i = 1; i <= n * m; i++)
    if (p[i].data == p[i - 1].data && p[i].x == p[i - 1].x)
      f[find(p[i].id)] = find(p[i - 1].id);
  sort(p + 1, p + 1 + n * m, cmpy);
  for (int i = 1; i <= n * m; i++)
    if (p[i].data == p[i - 1].data && p[i].y == p[i - 1].y)
      f[find(p[i].id)] = find(p[i - 1].id);
  for (int i = 1; i <= n * m; i++)
    h[find(i)].push_back(rec[i].x), l[find(i)].push_back(rec[i].y);
  for (int i = 1; i <= n * m; i++) {
    if (ans[x = find(p[i].id)]) continue;
    int sizex = h[x].size(), sizey = l[x].size(), tmp = 0;
    for (int i = 0; i < sizex; i++) tmp = max(tmp, hs[h[x][i]]);
    for (int i = 0; i < sizey; i++) tmp = max(tmp, ls[l[x][i]]);
    tmp++;
    ans[x] = tmp;
    for (int i = 0; i < sizex; i++) hs[h[x][i]] = tmp;
    for (int i = 0; i < sizey; i++) ls[l[x][i]] = tmp;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) printf("%d ", ans[find((i - 1) * m + j)]);
    putchar('\n');
  }
  return 0;
}
