#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> rows(N);
  vector<int> columns(M);
  vector<vector<int>> matrix(N, vector<int>(M));
  vector<vector<int>> row_adjList(N);
  vector<vector<int>> col_adjList(M);
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      Q;
  for (int i = 0; i < N * M; i++) {
    int A;
    cin >> A;
    Q.emplace(A, i);
  }
  while (!Q.empty()) {
    pair<int, int> curr = Q.top();
    Q.pop();
    int A = curr.first;
    vector<int> Same{curr.second};
    while (!Q.empty() and Q.top().first == A) {
      Same.push_back(Q.top().second);
      Q.pop();
    }
    if (Same.size() == 1) {
      int X = Same[0];
      int r = X / M;
      int c = X % M;
      int maxVal = max(rows[r] + 1, columns[c] + 1);
      matrix[r][c] = maxVal;
      columns[c] = rows[r] = maxVal;
      continue;
    }
    vector<bool> visited(Same.size());
    for (int i = 0; i < Same.size(); i++) {
      int X = Same[i];
      int r = X / M;
      int c = X % M;
      row_adjList[r].push_back(i);
      col_adjList[c].push_back(i);
    }
    for (int i = 0; i < Same.size(); i++) {
      if (visited[i] == 1) continue;
      visited[i] = 1;
      vector<int> component{Same[i]};
      deque<int> Q{i};
      while (!Q.empty()) {
        int curr_i = Q.front();
        Q.pop_front();
        int X = Same[curr_i];
        int r = X / M;
        int c = X % M;
        for (int Y : row_adjList[r]) {
          if (visited[Y] == 0) {
            visited[Y] = 1;
            component.push_back(Same[Y]);
            Q.push_back(Y);
          }
        }
        row_adjList[r].clear();
        for (int Y : col_adjList[c]) {
          if (visited[Y] == 0) {
            visited[Y] = 1;
            component.push_back(Same[Y]);
            Q.push_back(Y);
          }
        }
        col_adjList[c].clear();
      }
      int maxVal = 0;
      for (int X : component) {
        int r = X / M;
        int c = X % M;
        int val = rows[r] + 1;
        val = max(val, columns[c] + 1);
        maxVal = max(val, maxVal);
      }
      for (int X : component) {
        int r = X / M;
        int c = X % M;
        matrix[r][c] = maxVal;
        columns[c] = rows[r] = maxVal;
      }
    }
  }
  for (int r = 0; r < N; r++) {
    for (int c = 0; c < M; c++) {
      if (c != 0) cout << " ";
      cout << matrix[r][c];
    }
    cout << '\n';
  }
}
