#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 9;
int n, m, r[N], c[N];
vector<pair<int, pair<int, int> > > v;
vector<vector<int> > a;
vector<int> go[N][2];
map<pair<int, int>, int> vis;
vector<pair<int, int> > cmp;
void dfs(pair<int, int> node, int &mx) {
  cmp.push_back(node);
  vis[node]++;
  mx = max(mx, max(r[node.first], c[node.second]));
  while (!go[node.first][0].empty()) {
    int x = go[node.first][0].back();
    go[node.first][0].pop_back();
    dfs({node.first, x}, mx);
  }
  while (!go[node.second][1].empty()) {
    int x = go[node.second][1].back();
    go[node.second][1].pop_back();
    dfs({x, node.second}, mx);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  a.resize(n + 6, vector<int>(m + 6));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int x;
      cin >> x;
      v.push_back({x, {i, j}});
    }
  sort(v.rbegin(), v.rend());
  while (!v.empty()) {
    int val = v.back().first;
    vector<pair<int, int> > cur;
    while (!v.empty() && v.back().first == val) {
      cur.push_back(v.back().second);
      v.pop_back();
      go[cur.back().first][0].push_back(cur.back().second);
      go[cur.back().second][1].push_back(cur.back().first);
    }
    for (auto i : cur) {
      if (!vis[i]) {
        int mx = 0;
        dfs(i, mx);
        for (auto j : cmp)
          a[j.first][j.second] = mx + 1, r[j.first] = mx + 1,
          c[j.second] = mx + 1;
        cmp.clear();
      }
    }
    vis.clear();
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cout << a[i][j] << " ";
    cout << "\n";
  }
}
