#include <bits/stdc++.h>
using namespace std;
int n, m;
int cnt;
struct data {
  int r, c, val, id;
} a[1000001];
int res[1000001];
int k[1000001], p[1000001];
int rmax[1000001], cmax[1000001];
bool cmp(data X, data Y) { return X.val < Y.val; }
int Find(int x) {
  if (p[x] == x) return x;
  return p[x] = Find(p[x]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cnt++;
      cin >> a[cnt].val;
      k[cnt] = a[cnt].val;
      a[cnt].id = (i - 1) * m + j;
      a[cnt].r = i;
      a[cnt].c = j;
    }
  sort(a + 1, a + 1 + cnt, cmp);
  for (int i = 1; i <= cnt; i++) p[i] = i;
  for (int i = 1; i <= cnt; i++) {
    int id = a[i].id, r = a[i].r, c = a[i].c, val = a[i].val;
    int fr = Find(rmax[r]), fc = Find(cmax[c]);
    res[id] = max(res[fr] + 1 * (val > k[fr]), res[fc] + 1 * (val > k[fc]));
    if (val == k[fr]) p[fr] = id;
    if (val == k[fc]) p[fc] = id;
    rmax[r] = id;
    cmax[c] = id;
  }
  for (int i = 1; i <= cnt; i++) {
    cout << res[Find(i)] << " ";
    if (i % m == 0) cout << "\n";
  }
}
