#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> A(n, vector<int>(m));
  for (auto& row : A) {
    for (auto& a : row) {
      cin >> a;
    }
  }
  set<int> X, Y;
  for (int i = 0; i < n; ++i) {
    int x = A[i][0];
    for (int j = 0; j < m; ++j) {
      x = max(x, A[i][j]);
    }
    X.insert(x);
  }
  for (int j = 0; j < m; ++j) {
    int y = A[0][j];
    for (int i = 0; i < n; ++i) {
      y = max(y, A[i][j]);
    }
    Y.insert(y);
  }
  queue<pair<int, int>> pos_queue;
  vector<vector<int>> B(n, vector<int>(m));
  int cur_i = -1, cur_j = -1;
  for (int b = n * m; b > 0; --b) {
    if (X.count(b) && Y.count(b)) {
      cur_i++;
      cur_j++;
      B[cur_i][cur_j] = b;
      for (int j = cur_j - 1; j >= 0; --j) {
        pos_queue.push({cur_i, j});
      }
      for (int i = cur_i - 1; i >= 0; --i) {
        pos_queue.push({i, cur_j});
      }
    } else if (X.count(b)) {
      cur_i++;
      B[cur_i][cur_j] = b;
      for (int j = cur_j - 1; j >= 0; --j) {
        pos_queue.push({cur_i, j});
      }
    } else if (Y.count(b)) {
      cur_j++;
      B[cur_i][cur_j] = b;
      for (int i = cur_i - 1; i >= 0; --i) {
        pos_queue.push({i, cur_j});
      }
    } else {
      B[pos_queue.front().first][pos_queue.front().second] = b;
      pos_queue.pop();
    }
  }
  for (const auto& row : B) {
    for (const auto& b : row) {
      cout << b << " ";
    }
    cout << "\n";
  }
}
