#include <bits/stdc++.h>
using namespace std;
const int N = 250, M = 250;
int ii[1 + N * M], jj[1 + N * M], qu[N * M], aa[N][M];
bool row[N], col[M];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int a;
      cin >> a;
      ii[a] = i, jj[a] = j;
    }
  int head = 0, cnt = 0;
  int i_ = -1, j_ = -1;
  for (int a = n * m; a >= 1; a--) {
    int i = ii[a], j = jj[a];
    if (!row[i] && !col[j]) {
      row[i] = col[j] = true;
      aa[++i_][++j_] = a;
      for (i = i_ - 1; i >= 0; i--) qu[head + cnt++] = i * m + j_;
      for (j = j_ - 1; j >= 0; j--) qu[head + cnt++] = i_ * m + j;
    } else if (!row[i]) {
      row[i] = true;
      aa[++i_][j_] = a;
      for (j = j_ - 1; j >= 0; j--) qu[head + cnt++] = i_ * m + j;
    } else if (!col[j]) {
      col[j] = true;
      aa[i_][++j_] = a;
      for (i = i_ - 1; i >= 0; i--) qu[head + cnt++] = i * m + j_;
    } else {
      int h = qu[cnt--, head++];
      i = h / m, j = h % m;
      aa[i][j] = a;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << aa[i][j] << ' ';
    cout << '\n';
  }
  return 0;
}
