#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int N = 1010000;
int n, m, mr[N], mc[N];
pair<int, pair<int, int> > p[N];
int val[N], dp[N], f[N];
vector<int> num[N], e[N];
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      scanf("%d", &p[i * m + j].first);
      p[i * m + j].second = make_pair(i, j);
      val[i * m + j] = p[i * m + j].first;
      f[i * m + j] = i * m + j;
    }
  sort(p, p + n * m);
  for (int i = 0; i < n; i++) mr[i] = -1;
  for (int i = 0; i < m; i++) mc[i] = -1;
  for (int i = 0; i < n * m; i++) {
    int r = p[i].second.first, c = p[i].second.second;
    if (mr[r] != -1) {
      if (val[mr[r]] == p[i].first)
        f[find(r * m + c)] = find(mr[r]);
      else
        e[r * m + c].push_back(mr[r]);
    }
    if (mc[c] != -1) {
      if (val[mc[c]] == p[i].first)
        f[find(r * m + c)] = find(mc[c]);
      else
        e[r * m + c].push_back(mc[c]);
    }
    mr[r] = r * m + c;
    mc[c] = r * m + c;
  }
  for (int i = 0; i < n * m; i++) num[find(i)].push_back(i);
  for (int i = 0; i < n * m; i++) {
    int r = p[i].second.first, c = p[i].second.second, id = r * m + c;
    if (find(id) == id) {
      int ret = 0;
      for (unsigned int j = 0; j < num[id].size(); j++)
        for (unsigned int k = 0; k < e[num[id][j]].size(); k++)
          ret = max(ret, dp[e[num[id][j]][k]]);
      for (unsigned int j = 0; j < num[id].size(); j++)
        dp[num[id][j]] = ret + 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) printf("%d ", dp[i * m + j]);
    puts("");
  }
}
