#include <bits/stdc++.h>
const int N = 1000100;
using namespace std;
int n, m;
vector<vector<int>> a;
set<int> st;
map<int, int> w;
vector<pair<int, int>> v[N];
int maxI[N], maxJ[N], updI[N], updJ[N], mustI[N], mustJ[N];
int max(int a, int b) { return a > b ? a : b; }
int min(int a, int b) { return a < b ? a : b; }
int main() {
  scanf("%d%d", &n, &m);
  a.resize(n);
  for (int i = 0; i < n; ++i) {
    a[i].resize(m);
    for (int j = 0; j < m; ++j) {
      scanf("%d", &a[i][j]);
      st.insert(a[i][j]);
    }
  }
  int k = 0;
  for (auto& it : st) w[it] = ++k;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      a[i][j] = w[a[i][j]];
      v[a[i][j]].emplace_back(i, j);
    }
  for (int i = 1; i <= k; ++i) {
    int val = 0;
    for (auto& p : v[i]) {
      int x = p.first, y = p.second;
      int val = max(maxI[x], maxJ[y]) + 1;
      if (updI[x] != i) mustI[x] = val;
      if (updJ[y] != i) mustJ[y] = val;
      updI[x] = i;
      updJ[y] = i;
      mustI[x] = max(val, mustI[x]);
      mustJ[y] = max(val, mustJ[y]);
    }
    for (auto& p : v[i]) {
      int x = p.first, y = p.second;
      int val = max(maxI[x], maxJ[y]) + 1;
      if (updI[x] == i) val = max(val, mustI[x]);
      if (updJ[y] == i) val = max(val, mustJ[y]);
      a[x][y] = val;
    }
    for (auto& p : v[i]) {
      int x = p.first, y = p.second;
      maxI[x] = max(a[x][y], maxI[x]);
      maxJ[y] = max(a[x][y], maxJ[y]);
    }
    bool f = true;
    while (f) {
      f = false;
      for (auto& p : v[i]) {
        int x = p.first, y = p.second;
        if (max(maxI[x], maxJ[y]) > a[x][y]) f = true;
        a[x][y] = max(maxI[x], maxJ[y]);
        maxI[x] = max(a[x][y], maxI[x]);
        maxJ[y] = max(a[x][y], maxJ[y]);
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) printf("%d ", a[i][j]);
    printf("\n");
  }
  return 0;
}
