#include <bits/stdc++.h>
using namespace std;
const int N(1e6 + 5);
struct node {
  int x, y, v;
  bool operator<(const node &a) const { return v < a.v; }
} a[N], mx[N], my[N];
int par[N], ma[N], ans[N];
int m, n;
int ID(node &a) { return a.x * m + a.y; }
int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); }
void unite(int x, int y) {
  x = find(x), y = find(y);
  par[x] = y;
  ma[y] = max(ma[y], ma[x]);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= m; j++) {
      int x;
      cin >> x;
      a[i * m + j] = {i, j, x};
    }
  }
  for (int i = 1; i <= m * n; i++) par[i] = i;
  sort(a + 1, a + m * n + 1);
  for (int i = 1, j; i <= m * n;) {
    for (j = i; j <= m * n && a[j].v == a[i].v; j++) {
      ma[ID(a[j])] = max(ans[ID(mx[a[j].x])], ans[ID(my[a[j].y])]);
      if (a[j].v == mx[a[j].x].v) {
        unite(ID(a[j]), ID(mx[a[j].x]));
      } else {
        mx[a[j].x] = a[j];
      }
      if (a[j].v == my[a[j].y].v) {
        unite(ID(a[j]), ID(my[a[j].y]));
      } else {
        my[a[j].y] = a[j];
      }
    }
    for (; i != j; i++) {
      int id = ID(a[i]);
      ans[id] = ma[find(id)] + 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= m; j++) cout << ans[i * m + j] << ' ';
    cout << '\n';
  }
  return 0;
}
