#include <bits/stdc++.h>
using namespace std;
char buf[1048576], *p0, *p1;
inline int read() {
  int r = 0;
  char c =
      (p0 == p1 && (p1 = (p0 = buf) + fread(buf, 1, 1048576, stdin), p0 == p1)
           ? EOF
           : *p0++);
  while (c < 48 || c > 57)
    c = (p0 == p1 && (p1 = (p0 = buf) + fread(buf, 1, 1048576, stdin), p0 == p1)
             ? EOF
             : *p0++);
  while (c > 47 && c < 58) {
    r = (r << 3) + (r << 1) + (c ^ 48);
    c = (p0 == p1 && (p1 = (p0 = buf) + fread(buf, 1, 1048576, stdin), p0 == p1)
             ? EOF
             : *p0++);
  }
  return r;
}
int a[1005][1005], b[2][1005], p[1005][1005];
bool f[2][1000005];
queue<pair<int, int> > q;
int main() {
  int n = read(), m, r = -1, c = -1;
  m = read();
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      b[0][i] = max(b[0][i], a[i][j] = read());
      b[1][j] = max(b[1][j], a[i][j]);
    }
  for (int i = 0; i < n; ++i) f[0][b[0][i]] = true;
  for (int i = 0; i < m; ++i) f[1][b[1][i]] = true;
  for (int i = n * m; i; --i) {
    if (f[0][i]) ++r;
    if (f[1][i]) ++c;
    if (f[0][i] || f[1][i])
      p[r][c] = i;
    else {
      p[q.front().first][q.front().second] = i;
      q.pop();
    }
    if (f[0][i])
      for (int j = c - 1; j >= 0; --j) q.emplace(r, j);
    if (f[1][i])
      for (int j = r - 1; j >= 0; --j) q.emplace(j, c);
  }
  for (int i = 0; i < n; ++i, putchar(10))
    for (int j = 0; j < m; ++j) printf("%d ", p[i][j]);
  return 0;
}
