#include <bits/stdc++.h>
using namespace std;
struct Node {
  int x;
  int y;
  int value;
} b[1000000 + 5];
int n, m;
int cmp(Node a, Node b) { return a.value < b.value; }
int father[1000000 + 5];
int r[1000000 + 5];
int l[1000000 + 5];
int mr[1000000 + 5];
int ml[1000000 + 5];
int ans[1000000 + 5];
int get(int x) {
  if (x != father[x]) father[x] = get(father[x]);
  return father[x];
}
void join(int x, int y) {
  int fx = get(x);
  int fy = get(y);
  if (fx != fy) father[fx] = fy;
}
int main() {
  scanf("%d%d", &n, &m);
  int cnt = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &b[(i - 1) * m + j].value);
      b[cnt].x = i;
      b[cnt++].y = j;
    }
  }
  sort(b + 1, b + n * m + 1, cmp);
  for (int i = 1; i <= n * m; i++) father[i] = i;
  int i = 1, k;
  while (i <= n * m) {
    for (k = i; k <= n * m; k++) {
      if (b[k].value != b[i].value) break;
    }
    for (int j = i; j < k; j++) {
      if (!r[b[j].x])
        r[b[j].x] = (b[j].x - 1) * m + b[j].y;
      else {
        join(r[b[j].x], (b[j].x - 1) * m + b[j].y);
      }
      if (!l[b[j].y])
        l[b[j].y] = (b[j].x - 1) * m + b[j].y;
      else {
        join(l[b[j].y], (b[j].x - 1) * m + b[j].y);
      }
    }
    for (int j = i; j < k; j++) {
      int s = get((b[j].x - 1) * m + b[j].y);
      ans[s] = max(ans[s], max(mr[b[j].x], ml[b[j].y]) + 1);
    }
    for (int j = i; j < k; j++) {
      int s = get((b[j].x - 1) * m + b[j].y);
      ans[(b[j].x - 1) * m + b[j].y] = ans[s];
      mr[b[j].x] = ans[s];
      ml[b[j].y] = ans[s];
      r[b[j].x] = 0;
      l[b[j].y] = 0;
    }
    i = k;
  }
  for (int i = 1; i <= n * m; i++) {
    if ((i) % m == 0)
      printf("%d\n", ans[i]);
    else
      printf("%d ", ans[i]);
  }
  return 0;
}
