#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000000;
struct UFT {
  int links[MAX_N], ranks[MAX_N], sizes[MAX_N];
  UFT() {}
  void init(int n) {
    for (int i = 0; i < n; i++) links[i] = i, ranks[i] = sizes[i] = 1;
  }
  int root(int i) {
    int i0 = i;
    while (links[i0] != i0) i0 = links[i0];
    return (links[i] = i0);
  }
  int rank(int i) { return ranks[root(i)]; }
  int size(int i) { return sizes[root(i)]; }
  bool same(int i, int j) { return root(i) == root(j); }
  int merge(int i0, int i1) {
    int r0 = root(i0), r1 = root(i1), mr;
    if (r0 == r1) return r0;
    if (ranks[r0] == ranks[r1]) {
      links[r1] = r0;
      sizes[r0] += sizes[r1];
      ranks[r0]++;
      mr = r0;
    } else if (ranks[r0] > ranks[r1]) {
      links[r1] = r0;
      sizes[r0] += sizes[r1];
      mr = r0;
    } else {
      links[r0] = r1;
      sizes[r1] += sizes[r0];
      mr = r1;
    }
    return mr;
  }
};
int gas[MAX_N], bs[MAX_N];
int has[MAX_N], vas[MAX_N], haps[MAX_N], vaps[MAX_N];
int hbs[MAX_N], vbs[MAX_N];
pair<int, int> aps[MAX_N];
UFT uft;
vector<int> gps[MAX_N];
int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  int n = h * w;
  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);
    aps[i] = pair<int, int>(ai, i);
  }
  sort(aps, aps + n);
  uft.init(n);
  for (int i = 0; i < n; i++) {
    int a = aps[i].first, p = aps[i].second;
    int x = p % w, y = p / w;
    if (has[y] == a) p = uft.merge(p, haps[y]);
    if (vas[x] == a) p = uft.merge(p, vaps[x]);
    gas[p] = has[y] = vas[x] = a;
    haps[y] = vaps[x] = p;
  }
  for (int i = 0; i < n; i++) gps[uft.root(i)].push_back(i);
  memset(has, 0, sizeof(has));
  memset(vas, 0, sizeof(vas));
  for (int i = 0; i < n; i++) {
    int a = aps[i].first, p = aps[i].second;
    if (gps[p].empty()) continue;
    vector<int> &gpp = gps[p];
    int ma = 0, mb = 0;
    for (vector<int>::iterator vit = gpp.begin(); vit != gpp.end(); vit++) {
      int x = *vit % w, y = *vit / w;
      ma = max(ma, max(has[y], vas[x]));
      mb = max(mb, max(hbs[y], vbs[x]));
    }
    int b = (ma < a) ? mb + 1 : mb;
    for (vector<int>::iterator vit = gpp.begin(); vit != gpp.end(); vit++) {
      int x = *vit % w, y = *vit / w;
      has[y] = vas[x] = a;
      hbs[y] = vbs[x] = bs[*vit] = b;
    }
  }
  for (int y = 0, p = 0; y < h; y++)
    for (int x = 0; x < w; x++, p++) {
      printf("%d", bs[p]);
      putchar(x + 1 < w ? ' ' : '\n');
    }
  return 0;
}
