#include <bits/stdc++.h>
using namespace std;
int n, m, father[1000010];
vector<int> a[1000010], num[1000010];
vector<pair<int, int> > wz[1000010];
map<int, int> mp;
map<int, int> ans, mxx, mxy;
priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int> >,
               greater<pair<pair<int, int>, int> > >
    pq;
int xy(int x, int y) { return (x - 1) * m + y; }
int findfather(int x) {
  if (father[x] == x)
    return father[x];
  else
    return father[x] = findfather(father[x]);
}
void ak(int aa, int bb) {
  int a1 = findfather(aa), b1 = findfather(bb);
  if (a1 != b1) father[a1] = b1;
}
int main() {
  int MX, len, i, j, val, x, y, cc, s1;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) {
    a[i].push_back(0);
    num[i].push_back(0);
    for (j = 1; j <= m; j++) {
      scanf("%d", &s1);
      a[i].push_back(s1);
      num[i].push_back(xy(i, j));
      pq.push(make_pair(make_pair(a[i][j], i), j));
    }
  }
  for (i = 1; i <= n * m; i++) father[i] = i;
  for (i = 1; i <= n; i++) {
    mp.clear();
    for (j = 1; j <= m; j++) {
      if (mp[a[i][j]] == 0)
        mp[a[i][j]] = findfather(num[i][j]);
      else
        ak(mp[a[i][j]], num[i][j]);
    }
  }
  for (j = 1; j <= m; j++) {
    mp.clear();
    for (i = 1; i <= n; i++) {
      if (mp[a[i][j]] == 0)
        mp[a[i][j]] = findfather(num[i][j]);
      else
        ak(mp[a[i][j]], num[i][j]);
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++)
      wz[findfather(num[i][j])].push_back(make_pair(i, j));
  }
  while (!pq.empty()) {
    pair<pair<int, int>, int> T = pq.top();
    pq.pop();
    val = T.first.first;
    x = T.first.second;
    y = T.second;
    if (ans[findfather(num[x][y])] == 0) {
      MX = 0;
      len = wz[findfather(num[x][y])].size();
      for (i = 0; i < len; i++) {
        MX = max(MX, max(mxx[wz[findfather(num[x][y])][i].first],
                         mxy[wz[findfather(num[x][y])][i].second]));
      }
      ans[findfather(num[x][y])] = MX + 1;
      cc = ans[findfather(num[x][y])];
      mxx[x] = max(mxx[x], cc);
      mxy[y] = max(mxy[y], cc);
    } else {
      cc = ans[findfather(num[x][y])];
      mxx[x] = max(mxx[x], cc);
      mxy[y] = max(mxy[y], cc);
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) printf("%d ", ans[findfather(num[i][j])]);
    printf("\n");
  }
  return 0;
}
