#include <bits/stdc++.h>
using namespace std;
const int maxn = 1001000;
int f[maxn], rx[maxn], ry[maxn], ans[maxn], pre_rx[maxn], pre_ry[maxn];
struct node {
  int num, x, y;
} mp[maxn];
int find(int x) {
  while (x != f[x]) x = f[x] = f[f[x]];
  return f[x];
}
void merge(int x, int y) {
  int xx = find(x), yy = find(y);
  if (xx != yy) f[yy] = xx;
}
bool cmp(node x, node y) { return x.num < y.num; }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int cnt = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%d", &mp[(i - 1) * m + j]);
      mp[cnt].x = i, mp[cnt++].y = j;
      f[(i - 1) * m + j] = (i - 1) * m + j;
    }
  sort(mp + 1, mp + n * m + 1, cmp);
  int k;
  for (int i = 1; i <= n * m; i = k) {
    for (k = i + 1; k <= n * m && mp[k].num == mp[i].num; k++)
      ;
    for (int j = i; j < k; j++) {
      int x = mp[j].x, y = mp[j].y;
      if (!rx[x])
        rx[x] = (x - 1) * m + y;
      else
        merge(rx[x], (x - 1) * m + y);
      if (!ry[y])
        ry[y] = (x - 1) * m + y;
      else
        merge(ry[y], (x - 1) * m + y);
    }
    for (int j = i; j < k; j++) {
      int x = mp[j].x, y = mp[j].y, r = find((x - 1) * m + y);
      ans[r] = max(ans[r], max(pre_rx[x], pre_ry[y]) + 1);
    }
    for (int j = i; j < k; j++) {
      int x = mp[j].x, y = mp[j].y, r = find((x - 1) * m + y);
      ans[(x - 1) * m + y] = ans[r];
      pre_rx[x] = pre_ry[y] = ans[r];
      rx[x] = 0, ry[y] = 0;
    }
  }
  for (int i = 1; i <= n * m; i++) {
    if (i % m == 0)
      printf("%d\n", ans[i]);
    else
      printf("%d ", ans[i]);
  }
  return 0;
}
