#include <bits/stdc++.h>
using namespace std;
const int MN = 2005;
int N, M, A[MN][MN], R[MN], C[MN], va[MN * MN], vb[MN * MN], x, y, ans[MN][MN];
queue<pair<int, int> > q;
inline void chkmax(int &x, int y) { x = max(x, y); }
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= M; ++j) {
      scanf("%d", &A[i][j]);
      chkmax(R[i], A[i][j]), chkmax(C[j], A[i][j]);
    }
  for (int i = 1; i <= N; ++i) va[R[i]] = 1;
  for (int i = 1; i <= M; ++i) vb[C[i]] = 1;
  for (int i = N * M; i >= 1; --i) {
    if (va[i]) ++x;
    if (vb[i]) ++y;
    if (va[i] || vb[i])
      ans[x][y] = i;
    else {
      ans[q.front().first][q.front().second] = i;
      q.pop();
    }
    if (va[i]) {
      for (int j = y - 1; j >= 1; --j) q.push(make_pair(x, j));
    }
    if (vb[i]) {
      for (int j = x - 1; j >= 1; --j) q.push(make_pair(j, y));
    }
  }
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= M; ++j) printf("%d ", ans[i][j]);
    printf("\n");
  }
  return 0;
}
