#include <bits/stdc++.h>
using namespace std;
int p[1200005], szs[1200005];
vector<pair<int, int> > v;
int nr[1200005], nc[1200005], ans[1200005];
vector<int> buf;
int find(int x) { return (p[x] == x) ? x : p[x] = find(p[x]); }
void merge(int x, int y) {
  x = find(x);
  y = find(y);
  if (szs[x] < szs[y]) {
    swap(x, y);
  }
  p[y] = x;
  szs[x] += szs[y];
}
int main() {
  int n, m, i, j;
  scanf("%d%d", &n, &m);
  int a[n + 4][m + 4];
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++)
      scanf("%d", &a[i][j]), v.push_back(make_pair(a[i][j], i * m + j));
  for (i = 0; i < n * m; i++) p[i] = i, szs[i] = 1;
  for (i = 0; i < n; i++) {
    map<int, int> mm;
    for (j = 0; j < m; j++) {
      if (mm.count(a[i][j])) merge(i * m + j, mm[a[i][j]]);
      mm[a[i][j]] = i * m + j;
    }
  }
  for (i = 0; i < m; i++) {
    map<int, int> mm;
    for (j = 0; j < n; j++) {
      if (mm.count(a[j][i])) merge(j * m + i, mm[a[j][i]]);
      mm[a[j][i]] = j * m + i;
    }
  }
  int pv, r, c, cur;
  sort(v.begin(), v.end());
  for (i = 0; i < v.size(); i++) {
    cur = v[i].second;
    pv = find(cur);
    r = cur / m;
    c = cur % m;
    int cx = nr[r];
    cx = max(cx, nc[c]);
    cx++;
    ans[pv] = max(ans[pv], cx);
    buf.push_back(cur);
    if (i == v.size() - 1 || v[i].first != v[i + 1].first) {
      for (j = 0; j < buf.size(); j++)
        nr[buf[j] / m] = ans[find(buf[j])], nc[buf[j] % m] = ans[find(buf[j])];
      buf.clear();
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) cout << ans[find(i * m + j)] << " ";
    cout << endl;
  }
  return 0;
}
