#include <bits/stdc++.h>
using namespace std;
int p[2000100], d[1000100], c[1000100], r[1000100], h[1000100];
struct P {
  int x, w;
  bool operator<(const P &hs) const { return x < hs.x; }
} a[1000100];
int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      scanf("%d", &a[i * m + j].x);
      a[i * m + j].w = i * m + j;
    }
  for (int i = 0; i < n * m; i++) p[i] = i;
  memset(r, 0, sizeof(0));
  memset(c, 0, sizeof(0));
  memset(d, 0, sizeof(0));
  sort(a, a + n * m);
  int t;
  for (int i = 0; i < n * m; i = t) {
    for (t = i; a[i].x == a[t].x; t++) {
      int xi = a[t].w / m;
      int yi = a[t].w % m;
      int x = find(xi + m);
      int y = find(yi);
      p[x] = y;
    }
    for (int j = i; j < t; j++) {
      int xi = a[j].w / m;
      int yi = a[j].w % m;
      int y = find(yi);
      d[y] = max(c[yi] + 1, d[y]);
      d[y] = max(r[xi] + 1, d[y]);
    }
    for (int j = i; j < t; j++) {
      int xi = a[j].w / m;
      int yi = a[j].w % m;
      int y = find(yi);
      c[yi] = r[xi] = d[y];
      h[a[j].w] = d[y];
    }
    for (int j = i; j < t; j++) {
      int xi = a[j].w / m;
      int yi = a[j].w % m;
      int y = find(yi);
      p[xi + m] = xi + m;
      p[yi] = yi;
      d[y] = 0;
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      printf("%d%c", h[i * m + j], j != (m - 1) ? ' ' : '\n');
  return 0;
}
