#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6;
vector<int> adj[MAXN + 5];
int ID[MAXN + 5];
int parent[MAXN + 5], height[MAXN + 5], sz[MAXN + 5];
void init(int n) {
  memset(height, 0, sizeof(height));
  for (int i = 0; i < n; i++) parent[i] = i, height[i] = 1, sz[i] = 1;
  return;
}
int find(int e) {
  if (parent[e] == e) return e;
  return parent[e] = find(parent[e]);
}
void join(int e1, int e2) {
  e1 = find(e1);
  e2 = find(e2);
  if (e1 == e2) return;
  if (height[e1] < height[e2]) swap(e1, e2);
  if (height[e1] == height[e2]) height[e1]++;
  parent[e2] = e1;
  sz[e1] += sz[e2];
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<vector<int> > grid(n, vector<int>(m));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &grid[i][j]);
  init(n * m);
  for (int i = 0; i < n; i++) {
    vector<pair<int, int> > temp;
    for (int j = 0; j < m; j++)
      temp.push_back(make_pair(grid[i][j], i * m + j));
    sort(temp.begin(), temp.end());
    for (int j = 1; j < m; j++)
      if (temp[j].first == temp[j - 1].first)
        join(temp[j].second, temp[j - 1].second);
  }
  for (int j = 0; j < m; j++) {
    vector<pair<int, int> > temp;
    for (int i = 0; i < n; i++)
      temp.push_back(make_pair(grid[i][j], i * m + j));
    sort(temp.begin(), temp.end());
    for (int i = 1; i < n; i++)
      if (temp[i].first == temp[i - 1].first)
        join(temp[i].second, temp[i - 1].second);
  }
  for (int i = 0; i < n; i++) {
    vector<pair<int, int> > temp;
    for (int j = 0; j < m; j++)
      temp.push_back(make_pair(grid[i][j], i * m + j));
    sort(temp.begin(), temp.end());
    for (int j = 1; j < m; j++)
      if (temp[j].first > temp[j - 1].first)
        adj[find(temp[j].second)].push_back(find(temp[j - 1].second));
  }
  for (int j = 0; j < m; j++) {
    vector<pair<int, int> > temp;
    for (int i = 0; i < n; i++)
      temp.push_back(make_pair(grid[i][j], i * m + j));
    sort(temp.begin(), temp.end());
    for (int i = 1; i < n; i++)
      if (temp[i].first > temp[i - 1].first)
        adj[find(temp[i].second)].push_back(find(temp[i - 1].second));
  }
  vector<pair<int, int> > all;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) all.push_back(make_pair(grid[i][j], i * m + j));
  memset(ID, -1, sizeof(ID));
  sort(all.begin(), all.end());
  for (int i = 0; i < all.size(); i++) {
    int e = find(all[i].second);
    if (ID[e] != -1) continue;
    int newval = 1;
    for (int k = 0; k < adj[e].size(); k++) {
      int child = adj[e][k];
      newval = max(newval, ID[child] + 1);
    }
    ID[e] = newval;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      printf("%d", ID[find(i * m + j)]);
      if (j == m - 1)
        printf("\n");
      else
        printf(" ");
    }
  return 0;
}
