#include <bits/stdc++.h>
using namespace std;
template <class X, class Y>
void minimize(X &x, const Y &y) {
  if (x > y) x = y;
}
template <class X, class Y>
void maximize(X &x, const Y &y) {
  if (x < y) x = y;
}
vector<vector<int> > board;
int m, n;
vector<pair<int, int> > adj[1000100];
vector<int> revAdj[1000100], comp[1000100];
int low[1000100], num[1000100], compID[1000100], cnt, nComp;
int f[1000100];
stack<int> st;
void loadGraph(void) {
  scanf("%d%d", &m, &n);
  board.assign(m + 1, vector<int>(n + 1, 0));
  for (int i = 0, _n = (m); i < _n; i = i + 1)
    for (int j = 0, _n = (n); j < _n; j = j + 1) scanf("%d", &board[i][j]);
  for (int i = 0, _n = (m); i < _n; i = i + 1) {
    vector<pair<int, int> > row;
    for (int j = 0, _n = (n); j < _n; j = j + 1)
      row.push_back(make_pair(board[i][j], j));
    sort((row).begin(), (row).end());
    for (int j = 0, _n = (n - 1); j < _n; j = j + 1) {
      int cur = ((i)*n + (row[j].second) + 1);
      int ___next = ((i)*n + (row[j + 1].second) + 1);
      if (row[j].first < row[j + 1].first) {
        adj[cur].push_back(make_pair(___next, 1));
      } else {
        adj[cur].push_back(make_pair(___next, 0));
        adj[___next].push_back(make_pair(cur, 0));
      }
    }
  }
  for (int j = 0, _n = (n); j < _n; j = j + 1) {
    vector<pair<int, int> > col;
    for (int i = 0, _n = (m); i < _n; i = i + 1)
      col.push_back(make_pair(board[i][j], i));
    sort((col).begin(), (col).end());
    for (int i = 0, _n = (m - 1); i < _n; i = i + 1) {
      int cur = ((col[i].second) * n + (j) + 1);
      int ___next = ((col[i + 1].second) * n + (j) + 1);
      if (col[i].first < col[i + 1].first) {
        adj[cur].push_back(make_pair(___next, 1));
      } else {
        adj[cur].push_back(make_pair(___next, 0));
        adj[___next].push_back(make_pair(cur, 0));
      }
    }
  }
  for (int i = (1), _b = (m * n); i <= _b; i = i + 1)
    for (__typeof((adj[i]).begin()) jt = (adj[i]).begin(); jt != (adj[i]).end();
         jt++)
      if (jt->second == 1) revAdj[jt->first].push_back(i);
}
void dfs(int u) {
  low[u] = num[u] = ++cnt;
  st.push(u);
  for (__typeof((adj[u]).begin()) it = (adj[u]).begin(); it != (adj[u]).end();
       it++)
    if (compID[it->first] == 0) {
      int v = it->first;
      if (num[v] == 0) {
        dfs(v);
        minimize(low[u], low[v]);
      } else
        minimize(low[u], num[v]);
    }
  if (low[u] == num[u]) {
    nComp++;
    int v;
    do {
      v = st.top();
      st.pop();
      compID[v] = nComp;
      comp[nComp].push_back(v);
    } while (v != u);
  }
}
int dp(int u) {
  if (f[u] >= 0) return (f[u]);
  f[u] = 1;
  for (__typeof((comp[u]).begin()) it = (comp[u]).begin();
       it != (comp[u]).end(); it++)
    for (__typeof((revAdj[*it]).begin()) jt = (revAdj[*it]).begin();
         jt != (revAdj[*it]).end(); jt++)
      maximize(f[u], dp(compID[*jt]) + 1);
  return (f[u]);
}
void process(void) {
  for (int i = (1), _b = (m * n); i <= _b; i = i + 1)
    if (num[i] == 0) dfs(i);
  memset(f, -1, sizeof f);
  for (int i = 0, _n = (m); i < _n; i = i + 1) {
    for (int j = 0, _n = (n); j < _n; j = j + 1)
      printf("%d ", dp(compID[((i)*n + (j) + 1)]));
    printf("\n");
  }
}
int main(void) {
  loadGraph();
  process();
  return 0;
}
