#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> table;
vector<int> result;
vector<int> parent;
vector<int> size;
int get_set(int v) {
  if (parent[v] == v)
    return v;
  else
    return parent[v] = get_set(parent[v]);
}
void union_sets(int a, int b) {
  a = get_set(a);
  b = get_set(b);
  if (size[a] < size[b]) swap(a, b);
  size[a] += size[b];
  parent[b] = a;
  return;
}
vector<vector<int>> gr;
int n, m;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  int i, j;
  table = vector<vector<int>>(n, vector<int>(m));
  result = vector<int>(n * m, -1);
  vector<vector<pair<int, int>>> mdk(n, vector<pair<int, int>>(m));
  vector<vector<pair<int, int>>> mdk2(m, vector<pair<int, int>>(n));
  int minval = 1000000001;
  for (i = 0; i < n; ++i)
    for (j = 0; j < m; ++j) {
      cin >> table[i][j];
      mdk[i][j].first = table[i][j];
      mdk[i][j].second = m * i + j;
      mdk2[j][i].first = table[i][j];
      mdk2[j][i].second = m * i + j;
      minval = min(minval, table[i][j]);
    }
  parent.resize(n * m);
  size.resize(n * m);
  gr.resize(n * m);
  vector<int> qnt(n * m);
  for (i = 0; i < n * m; ++i) {
    size[i] = 1;
    parent[i] = i;
  }
  for (i = 0; i < n; ++i) {
    sort(mdk[i].begin(), mdk[i].end());
    for (j = 1; j < m; ++j) {
      if (mdk[i][j - 1].first == mdk[i][j].first)
        union_sets(mdk[i][j - 1].second, mdk[i][j].second);
    }
  }
  for (j = 0; j < m; ++j) {
    sort(mdk2[j].begin(), mdk2[j].end());
    for (i = 1; i < n; ++i) {
      if (mdk2[j][i - 1].first == mdk2[j][i].first)
        union_sets(mdk2[j][i - 1].second, mdk2[j][i].second);
    }
  }
  for (i = 0; i < n; ++i)
    for (j = 1; j < m; ++j) {
      if (mdk[i][j - 1].first != mdk[i][j].first) {
        gr[get_set(mdk[i][j - 1].second)].push_back(get_set(mdk[i][j].second));
        qnt[get_set(mdk[i][j].second)]++;
      }
    }
  for (j = 0; j < m; ++j)
    for (i = 1; i < n; ++i) {
      if (mdk2[j][i - 1].first != mdk2[j][i].first) {
        gr[get_set(mdk2[j][i - 1].second)].push_back(
            get_set(mdk2[j][i].second));
        qnt[get_set(mdk2[j][i].second)]++;
      }
    }
  queue<pair<int, int>> putin;
  for (i = 0; i < n; ++i)
    for (j = 0; j < m; ++j) {
      if (i * m + j == get_set(i * m + j) && qnt[i * m + j] == 0)
        putin.push({i * m + j, 1});
    }
  while (!putin.empty()) {
    pair<int, int> temp = putin.front();
    putin.pop();
    result[temp.first] = temp.second;
    for (auto to : gr[temp.first]) {
      qnt[to]--;
      if (qnt[to] == 0) putin.push({to, temp.second + 1});
    }
  }
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m; ++j) {
      cout << result[get_set(i * m + j)] << ' ';
    }
    cout << "\n";
    ;
  }
  return 0;
}
