#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, x, y, v0[200010], v1[200010], R[502], C[502], a[502][502],
    b[502][502];
queue<int> q0, q1;
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++)
      R[i] = max(R[i], a[i][j]), C[j] = max(C[j], a[i][j]);
  }
  for (i = 1; i <= n; i++) v0[R[i]] = 1;
  for (i = 1; i <= m; i++) v1[C[i]] = 1;
  for (i = n * m; i; i--) {
    if (v0[i]) x++;
    if (v1[i]) y++;
    if (v0[i] || v1[i])
      b[x][y] = i;
    else
      b[q0.front()][q1.front()] = i, q0.pop(), q1.pop();
    if (v0[i]) {
      for (j = y - 1; j; j--) q0.push(x), q1.push(j);
    }
    if (v1[i]) {
      for (j = x - 1; j; j--) q0.push(j), q1.push(y);
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) printf("%d ", b[i][j]);
    puts("");
  }
}
