#include <bits/stdc++.h>
using namespace std;
struct disjoint_set {
  int par[1000005];
  int rnk[1000005];
  disjoint_set() {
    for (int i = 0; i < 1000000; i++) par[i] = i, rnk[i] = 0;
  }
  int find_par(int x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = find_par(par[x]);
  }
  bool join(int a, int b) {
    a = find_par(a), b = find_par(b);
    if (a == b) return 0;
    if (rnk[a] < rnk[b]) swap(a, b);
    if (rnk[a] == rnk[b]) rnk[a]++;
    par[b] = a;
    return 1;
  }
} dsu;
vector<vector<int> > g;
vector<int> adj[1000005];
int indeg[1000005];
vector<int> has[1000005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  g = vector<vector<int> >(n, vector<int>(m));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> g[i][j];
  for (int i = 0; i < n; i++) {
    map<int, int> av;
    for (int j = 0; j < m; j++) {
      if (av.count(g[i][j]))
        dsu.join(av[g[i][j]], i * m + j);
      else
        av[g[i][j]] = i * m + j;
    }
  }
  for (int j = 0; j < m; j++) {
    map<int, int> av;
    for (int i = 0; i < n; i++) {
      if (av.count(g[i][j]))
        dsu.join(av[g[i][j]], i * m + j);
      else
        av[g[i][j]] = i * m + j;
    }
  }
  for (int i = 0; i < n; i++) {
    vector<pair<int, int> > temp;
    for (int j = 0; j < m; j++) {
      temp.push_back(make_pair(g[i][j], i * m + j));
      has[dsu.find_par(i * m + j)].push_back(i * m + j);
    }
    sort(temp.begin(), temp.end());
    for (int j = 1; j < temp.size(); j++) {
      if (temp[j].first == temp[j - 1].first) continue;
      int a = dsu.find_par(temp[j - 1].second);
      int b = dsu.find_par(temp[j].second);
      adj[a].push_back(b);
      indeg[b]++;
    }
  }
  for (int j = 0; j < m; j++) {
    vector<pair<int, int> > temp;
    for (int i = 0; i < n; i++) {
      temp.push_back(make_pair(g[i][j], i * m + j));
      has[dsu.find_par(i * m + j)].push_back(i * m + j);
    }
    sort(temp.begin(), temp.end());
    for (int i = 1; i < temp.size(); i++) {
      if (temp[i].first == temp[i - 1].first) continue;
      int a = dsu.find_par(temp[i - 1].second);
      int b = dsu.find_par(temp[i].second);
      adj[a].push_back(b);
      indeg[b]++;
    }
  }
  queue<int> stk;
  for (int i = 0; i < n * m; i++)
    if (has[i].size() && indeg[i] == 0) stk.push(i);
  int lst = 0;
  while (stk.size()) {
    int s = stk.size();
    lst++;
    while (s--) {
      int cur = stk.front();
      stk.pop();
      for (int i = 0; i < has[cur].size(); i++) {
        int temp = has[cur][i];
        g[temp / m][temp % m] = lst;
      }
      for (int i = 0; i < adj[cur].size(); i++) {
        int t = adj[cur][i];
        indeg[t]--;
        if (indeg[t] == 0) stk.push(t);
      }
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cout << g[i][j] << " \n"[j == m - 1];
  return 0;
}
