#include <bits/stdc++.h>   using namespace std;   template <class T, class L>   bool smax(T& x, L y) {     return x < y ? (x = y, 1) : 0;   }   template <class T, class L>   bool smin(T& x, L y) {     return x > y ? (x = y, 1) : 0;   }   const int maxn = 2e6 + 17;   pair<int, pair<int, int> > a[maxn];   int n, m, par[maxn], mx[maxn], here[maxn];   map<pair<int, int>, int> ans;   int r(int v) { return par[v] < 0 ? v : par[v] = r(par[v]); }   void mrg(int v, int u) {     if ((v = r(v)) == (u = r(u))) return;     if (par[u] < par[v]) swap(v, u);     par[v] += par[u];     par[u] = v;     smax(mx[v], mx[u]);   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0, x; j < m; j++) cin >> x, a[i * m + j] = {x, {i, j}};     sort(a, a + n * m);     for (int l = 0; l < n * m;) {       int r = l;       while (a[r].first == a[l].first) r++;       for (int i = l; i < r; i++) {         mx[a[i].second.first] = mx[a[i].second.second + n] = 0;         par[a[i].second.first] = par[a[i].second.second + n] = -1;       }       for (int i = l; i < r; i++)         smax(mx[a[i].second.first],              max(here[a[i].second.first], here[a[i].second.second + n]) + 1);       for (int i = l; i < r; i++) mrg(a[i].second.first, a[i].second.second + n);       for (int i = l; i < r; i++) {         ans[{a[i].second.first, a[i].second.second}] = mx[::r(a[i].second.first)];         smax(here[a[i].second.first],              ans[{a[i].second.first, a[i].second.second}]);         smax(here[a[i].second.second + n],              ans[{a[i].second.first, a[i].second.second}]);       }       l = r;     }     for (int i = 0; i < n; i++, cout <<   n )       for (int j = 0; j < m; j++) cout << ans[{i, j}] <<    ;     return 0;   }   