#include <bits/stdc++.h>
using namespace std;
int num[305][305], ans[305][305];
bool inr[90005], inc[90005];
int lpos[305], rpos[305];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &num[i][j]);
  for (int i = 1; i <= n; i++) {
    int maxn = 0;
    for (int j = 1; j <= m; j++) maxn = max(maxn, num[i][j]);
    inr[maxn] = 1;
  }
  for (int i = 1; i <= m; i++) {
    int maxn = 0;
    for (int j = 1; j <= n; j++) maxn = max(maxn, num[j][i]);
    inc[maxn] = 1;
  }
  int dx = 0, dy = 0;
  for (int i = n * m; i > 0; i--)
    if (inr[i] && inc[i]) {
      dx++;
      dy++;
      ans[dx][dy] = i;
      lpos[dx] = rpos[dx] = dy;
    } else if (inr[i]) {
      dx++;
      ans[dx][dy] = i;
      lpos[dx] = rpos[dx] = dy;
    } else if (inc[i]) {
      dy++;
      ans[dx][dy] = i;
      rpos[dx] = dy;
    } else {
      bool ok = 0;
      for (int j = 1; j <= dx; j++)
        if (lpos[j] > 1) {
          lpos[j]--;
          ans[j][lpos[j]] = i;
          ok = 1;
          break;
        }
      if (ok) continue;
      for (int j = dx; j > 0; j--)
        if (rpos[j] < dy) {
          rpos[j]++;
          ans[j][rpos[j]] = i;
          ok = 1;
          break;
        }
    }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) printf("%d ", ans[i][j]);
    printf("\n");
  }
  return 0;
}
