#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
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));
  vector<int> maxR(n), maxC(m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
      maxR[i] = max(maxR[i], A[i][j]);
      maxC[j] = max(maxC[j], A[i][j]);
    }
  unordered_set<int> specX(maxR.begin(), maxR.end()),
      specY(maxC.begin(), maxC.end());
  vector<vector<int> > out(n, vector<int>(m));
  queue<pair<int, int> > pos;
  int x = -1, y = -1;
  for (int t = n * m; t > 0; t--) {
    bool sx = specX.find(t) != specX.end();
    bool sy = specY.find(t) != specY.end();
    if (sx) x++;
    if (sy) y++;
    if (sx || sy)
      out[x][y] = t;
    else {
      out[pos.front().first][pos.front().second] = t;
      pos.pop();
    }
    if (sx)
      for (int ny = y - 1; ny >= 0; ny--) pos.push(make_pair(x, ny));
    if (sy)
      for (int nx = x - 1; nx >= 0; nx--) pos.push(make_pair(nx, y));
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << out[i][j] << " ";
    cout << "\n";
  }
  return 0;
}
