#include <bits/stdc++.h>
using namespace std;
const long long int INF = (1LL << 58);
const bool DEBUG = 0;
const int MAX_LIMIT = 1000006;
int rows, cols;
std::vector<vector<pair<int, int> > > row;
std::vector<int> adj[MAX_LIMIT];
std::vector<vector<int> > mat, idMatrix;
int val[MAX_LIMIT];
map<int, int> rowPresence[MAX_LIMIT], colPresence[MAX_LIMIT];
int idMapping[MAX_LIMIT];
void dfs(int node) {
  int i, limit = adj[node].size();
  if (limit == 0) val[node] = 1;
  for (i = 0; i < limit; i++) {
    int v = adj[node][i];
    if (!val[v]) dfs(v);
    val[node] = max(val[node], val[v] + 1);
  }
  return;
}
const int NODES_LIMIT = 1000006;
class DSU {
 public:
  int par[NODES_LIMIT], size[NODES_LIMIT];
  void init(int noOfItems) {
    for (int i = 0; i < noOfItems; i++) {
      par[i] = i;
      size[i] = 1;
    }
  }
  int getRoot(int node) {
    if (par[node] == node) return node;
    return par[node] = getRoot(par[node]);
  }
  void merge(int u, int v) {
    int root[2] = {getRoot(u), getRoot(v)};
    if (root[0] == root[1]) return;
    if (size[root[0]] < size[root[1]]) swap(root[0], root[1]);
    size[root[0]] += size[root[1]];
    par[root[1]] = root[0];
  }
};
int getCellId(int x, int y) { return (x * cols + y) + 1; }
int main() {
  int i, j;
  scanf("%d", &rows);
  scanf("%d", &cols);
  DSU d;
  d.init(rows * cols + 2);
  row.resize(rows + cols);
  mat.resize(rows);
  idMatrix.resize(rows);
  for (i = 0; i < rows; i++) {
    idMatrix[i].resize(cols);
    mat[i].resize(cols);
  }
  int id = 1;
  for (i = 0; i < rows; i++) {
    for (j = 0; j < cols; j++) {
      int temp;
      scanf("%d", &temp);
      mat[i][j] = temp;
      rowPresence[i][temp] = getCellId(i, j);
      colPresence[j][temp] = getCellId(i, j);
    }
  }
  for (i = 0; i < rows; i++) {
    for (j = 0; j < cols; j++) {
      int x = mat[i][j];
      int thisCellId = getCellId(i, j);
      int toMergeWith = rowPresence[i][x];
      d.merge(thisCellId, toMergeWith);
      toMergeWith = colPresence[j][x];
      d.merge(thisCellId, toMergeWith);
    }
  }
  for (i = 0; i < rows; i++) {
    for (j = 0; j < cols; j++) {
      int thisCellId = getCellId(i, j);
      if (thisCellId == d.getRoot(thisCellId)) idMapping[thisCellId] = id++;
    }
  }
  for (i = 0; i < rows; i++) rowPresence[i].clear();
  for (j = 0; j < cols; j++) colPresence[j].clear();
  for (i = 0; i < rows; i++) {
    for (j = 0; j < cols; j++) {
      int thisCellId = getCellId(i, j);
      idMatrix[i][j] = idMapping[d.getRoot(getCellId(i, j))];
      row[i].push_back(make_pair(mat[i][j], idMatrix[i][j]));
      row[rows + j].push_back(make_pair(mat[i][j], idMatrix[i][j]));
    }
  }
  mat.clear();
  for (i = 0; i < row.size(); i++) {
    sort(row[i].begin(), row[i].end());
    for (j = 0; j < row[i].size() - 1; j++) {
      int u = row[i][j + 1].second;
      int v = row[i][j].second;
      if (u != v) adj[u].push_back(v);
    }
  }
  row.clear();
  for (i = 1; i < id; i++)
    if (val[i] == 0) dfs(i);
  for (i = 0; i < rows; i++) {
    for (j = 0; j < cols; j++) printf("%d ", val[idMatrix[i][j]]);
    printf("\n");
  }
  return 0;
}
