#include <bits/stdc++.h>
using namespace std;
int a[333][333], cur = 0;
int vis[333 * 333];
int ans[333][333];
void swapc(int x, int y, int n) {
  for (int i = 0; i < n; ++i) swap(a[i][x], a[i][y]);
}
void swapr(int x, int y, int m) {
  for (int i = 0; i < m; ++i) swap(a[x][i], a[y][i]);
}
void gao(int n, int m) {
  if (n == 0 || m == 0) return;
  int Minr = 333 * 333, Minc = 333 * 333, idxr, idxc;
  for (int i = 0; i < n; ++i) {
    int tp = a[i][0];
    for (int j = 1; j < m; ++j) tp = max(a[i][j], tp);
    if (Minr > tp) Minr = tp, idxr = i;
  }
  for (int i = 0; i < m; ++i) {
    int tp = a[0][i];
    for (int j = 1; j < n; ++j) tp = max(a[j][i], tp);
    if (Minc > tp) Minc = tp, idxc = i;
  }
  if (Minr == Minc) {
    swapr(idxr, n - 1, m);
    swapc(idxc, m - 1, n);
    ans[n - 1][m - 1] = Minr;
    vis[Minr] = 1;
    for (int i = 0; i < m - 1; ++i) {
      while (vis[++cur])
        ;
      ans[n - 1][i] = cur;
      vis[cur] = 1;
    }
    for (int i = 0; i < n - 1; ++i) {
      while (vis[++cur])
        ;
      ans[i][m - 1] = cur;
      vis[cur] = 1;
    }
    gao(n - 1, m - 1);
  } else if (Minr < Minc) {
    swapr(idxr, n - 1, m);
    ans[n - 1][m - 1] = Minr;
    vis[Minr] = 1;
    for (int i = 0; i < m - 1; ++i) {
      while (vis[++cur])
        ;
      vis[cur] = 1;
      ans[n - 1][i] = cur;
    }
    gao(n - 1, m);
  } else if (Minc < Minr) {
    swapc(idxc, m - 1, n);
    ans[n - 1][m - 1] = Minc;
    vis[Minc] = 1;
    for (int i = 0; i < n - 1; ++i) {
      while (vis[++cur])
        ;
      ans[i][m - 1] = cur;
      vis[cur] = 1;
    }
    gao(n, m - 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> a[i][j];
  gao(n, m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cout << ans[i][j] << " ";
    }
    cout << "\n";
  }
  return 0;
}
