#include <bits/stdc++.h>
using namespace std;
int p[1111111];
int sz[1111111];
int n, m;
vector<pair<int, int> > a;
int* b[1111111];
int get(int i) { return i == p[i] ? i : p[i] = get(p[i]); }
void uni(int u, int v) {
  u = get(u);
  v = get(v);
  if (sz[u] < sz[v]) {
    swap(u, v);
  }
  p[v] = u;
  sz[u] += sz[v];
}
int nc[1111111];
int nr[1111111];
int e[1111111];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    b[i] = new int[m];
  }
  for (int i = 0; i < n * m; ++i) {
    p[i] = i;
    sz[i] = 1;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> b[i][j];
      a.push_back(make_pair(b[i][j], i * m + j));
    }
  }
  for (int i = 0; i < n; ++i) {
    map<int, int> M;
    for (int j = 0; j < m; ++j) {
      if (M.count(b[i][j])) {
        uni(i * m + j, M[b[i][j]]);
      }
      M[b[i][j]] = i * m + j;
    }
  }
  for (int j = 0; j < m; ++j) {
    map<int, int> M;
    for (int i = 0; i < n; ++i) {
      if (M.count(b[i][j])) {
        uni(i * m + j, M[b[i][j]]);
      }
      M[b[i][j]] = i * m + j;
    }
  }
  sort(a.begin(), a.end());
  vector<int> buf;
  for (int i = 0; i < a.size(); ++i) {
    int ps = a[i].second;
    int should = nr[ps / m];
    should = max(should, nc[ps % m]);
    should++;
    e[get(ps)] = max(e[get(ps)], should);
    buf.push_back(ps);
    if (i == a.size() - 1 || a[i].first != a[i + 1].first) {
      for (int j = 0; j < buf.size(); ++j) {
        int x = buf[j];
        nr[x / m] = e[get(x)];
        nc[x % m] = e[get(x)];
      }
      buf.clear();
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cout << e[get(i * m + j)] << ' ';
    }
    cout << '\n';
  }
  return 0;
}
