#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
stringstream output;
inline void eOP();
inline void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> maxR(n);
  vector<int> maxC(m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int a;
      cin >> a;
      maxR[i] = max(maxR[i], a);
      maxC[j] = max(maxC[j], a);
    }
  }
  sort(maxR.begin(), maxR.end());
  sort(maxC.begin(), maxC.end());
  vector<bool> available(n * m + 1, true);
  vector<vector<int>> result(n, vector<int>(m));
  vector<pair<int, int>> keys;
  {
    int i = 0;
    int j = 0;
    {
      int v = maxR.back();
      maxR.pop_back();
      maxC.pop_back();
      result[i][j] = v;
      available[v] = false;
    }
    while (!maxR.empty() || !maxC.empty()) {
      int v;
      if (maxR.empty()) {
        ++j;
        v = maxC.back();
        maxC.pop_back();
      } else if (maxC.empty()) {
        ++i;
        v = maxR.back();
        maxR.pop_back();
      } else if (maxC.back() > maxR.back()) {
        ++j;
        v = maxC.back();
        maxC.pop_back();
      } else if (maxR.back() > maxC.back()) {
        ++i;
        v = maxR.back();
        maxR.pop_back();
      } else {
        ++i;
        ++j;
        v = maxR.back();
        maxR.pop_back();
        maxC.pop_back();
      }
      result[i][j] = v;
      available[v] = false;
      keys.emplace_back(i, j);
    }
  }
  int v = 1;
  for (auto rit = keys.rbegin(); rit != keys.rend(); ++rit) {
    int i = rit->first;
    int j = rit->second;
    for (int ii = 0; ii < n; ++ii) {
      if (result[ii][j]) {
        continue;
      }
      while (!available[v]) {
        ++v;
      }
      result[ii][j] = v;
      available[v] = false;
    }
    for (int jj = 0; jj < m; ++jj) {
      if (result[i][jj]) {
        continue;
      }
      while (!available[v]) {
        ++v;
      }
      result[i][jj] = v;
      available[v] = false;
    }
  }
  for (auto& row : result) {
    for (int e : row) {
      cout << e << " ";
    }
    cout << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  size_t t = 1;
  for (int i = 0; i < t; ++i) {
    solve();
  }
  eOP();
}
inline void eOP() {
  cout << output.str();
  output.str(string());
  exit(0);
}
