#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
vector<int> a[maxn];
vector<int> G[maxn];
vector<pair<int, int> > v, E;
queue<int> q;
int in[maxn];
int dis[maxn];
int fa[maxn];
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void Union(int x, int y) {
  int fx = find(x);
  int fy = find(y);
  if (fx != fy) fa[fx] = fy;
}
int main() {
  int n, m, x;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &x);
      a[i].push_back(x);
      fa[i * m + j] = i * m + j;
    }
  }
  for (int i = 0; i < n; i++) {
    v.clear();
    for (int j = 0; j < m; j++) v.push_back(pair<int, int>(a[i][j], i * m + j));
    sort(v.begin(), v.end());
    for (int j = 1; j < m; j++) {
      if (v[j - 1].first < v[j].first)
        E.push_back(pair<int, int>(v[j - 1].second, v[j].second));
      else
        Union(v[j - 1].second, v[j].second);
    }
  }
  for (int i = 0; i < m; i++) {
    v.clear();
    for (int j = 0; j < n; j++) v.push_back(pair<int, int>(a[j][i], j * m + i));
    sort(v.begin(), v.end());
    for (int j = 1; j < n; j++) {
      if (v[j - 1].first < v[j].first)
        E.push_back(pair<int, int>(v[j - 1].second, v[j].second));
      else
        Union(v[j - 1].second, v[j].second);
    }
  }
  for (int i = 0; i < E.size(); i++) {
    G[find(E[i].first)].push_back(find(E[i].second)), in[find(E[i].second)]++;
  }
  for (int i = 0; i < n * m; i++) {
    if (i == find(i) && !in[i]) {
      q.push(i);
      dis[i] = 1;
    }
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      dis[v] = max(dis[v], dis[u] + 1);
      in[v]--;
      if (!in[v]) q.push(v);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      printf("%d%c", dis[find(i * m + j)], (j == m - 1) ? '\n' : ' ');
    }
  }
  return 0;
}
