#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, m, k, t;
string s;
vector<int> a(1000005), b(1000005);
vector<vector<int>> mat(1005, vector<int>(1005)), res(1005, vector<int>(1005));
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> mat[i][j];
  for (int i = 0; i < n; i++) {
    int tmp = 0;
    for (int j = 0; j < m; j++) tmp = max(tmp, mat[i][j]);
    a[tmp] = 1;
  }
  for (int j = 0; j < m; j++) {
    int tmp = 0;
    for (int i = 0; i < n; i++) tmp = max(tmp, mat[i][j]);
    b[tmp] = 1;
  }
  queue<pair<int, int>> q;
  int x = -1, y = -1;
  for (int i = n * m; i >= 1; i--) {
    x += a[i], y += b[i];
    if (a[i] || b[i])
      res[x][y] = i;
    else {
      int xx = q.front().first, yy = q.front().second;
      q.pop(), res[xx][yy] = i;
    }
    if (a[i])
      for (int j = y - 1; j >= 0; j--) q.push(make_pair(x, j));
    if (b[i])
      for (int j = x - 1; j >= 0; j--) q.push(make_pair(j, y));
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << res[i][j] << " ";
    cout << endl;
  }
  return 0;
}
