#include <bits/stdc++.h>
using namespace std;
int par[1000006], parval[1000006];
pair<long long, int> row[1000006], col[1000006];
inline int parent(int pos) {
  if (par[pos] != pos) {
    par[pos] = parent(par[pos]);
  }
  return par[pos];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<long long> v[n], fans[n], comp;
  for (int i = 0; i < n; i++) {
    par[i] = i;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      long long x;
      cin >> x;
      v[i].push_back(x);
      comp.push_back(x);
      fans[i].push_back(0);
    }
  }
  sort(comp.begin(), comp.end());
  int sz = 1;
  map<long long, int> mp;
  for (int i = 0; i < comp.size(); i++) {
    if (!mp[comp[i]]) {
      mp[comp[i]] = sz;
      sz++;
    }
  }
  vector<pair<int, int> > g[sz + 1];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int k = mp[v[i][j]];
      g[k].push_back(make_pair(j, i));
    }
  }
  for (int i = 1; i < sz; i++) {
    sort(g[i].begin(), g[i].end());
    for (int j = 0; j < g[i].size(); j++) {
      pair<long long, int> p1 = row[g[i][j].second];
      pair<long long, int> p2 = col[g[i][j].first];
      if (p1.first == i) {
        parval[g[i][j].second] = max(parval[g[i][j].second], p1.second);
      } else {
        parval[g[i][j].second] = max(parval[g[i][j].second], p1.second + 1);
      }
      if (p2.first == i) {
        parval[g[i][j].second] = max(parval[g[i][j].second], p2.second);
      } else {
        parval[g[i][j].second] = max(parval[g[i][j].second], p2.second + 1);
      }
    }
    for (int j = 0; j < g[i].size() - 1; j++) {
      if (g[i][j].first == g[i][j + 1].first) {
        int p1 = parent(g[i][j].second);
        int p2 = parent(g[i][j + 1].second);
        if (p1 != p2) {
          par[max(p1, p2)] = min(p1, p2);
          parval[min(p1, p2)] = max(parval[p1], parval[p2]);
        }
      }
    }
    for (int j = 0; j < g[i].size(); j++) {
      int p1 = parent(g[i][j].second);
      fans[g[i][j].second][g[i][j].first] = parval[p1];
      row[g[i][j].second].second = col[g[i][j].first].second = parval[p1];
      row[g[i][j].second].first = col[g[i][j].first].first = i;
    }
    for (int j = 0; j < g[i].size(); j++) {
      par[g[i][j].second] = g[i][j].second;
      parval[g[i][j].first] = parval[g[i][j].second] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << fans[i][j] << " ";
    }
    cout << "\n";
  }
}
