#include <bits/stdc++.h>
using namespace std;
const int MAXN = 260;
int a[MAXN][MAXN];
int b[MAXN][MAXN];
int n, m;
void impossible() {
  cout << -1 << endl;
  exit(0);
}
void fillWeak(queue<pair<int, int> > &q, int rx, int lx) {
  for (int x = rx - 1; x > lx; x--) {
    assert(!q.empty());
    pair<int, int> p = q.front();
    q.pop();
    b[p.first][p.second] = x;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  vector<pair<int, int> > vp;
  for (int i = 1; i <= n; i++) {
    int mxid = 1;
    for (int j = 2; j <= m; j++) {
      if (a[i][j] > a[i][mxid]) mxid = j;
    }
    vp.emplace_back(a[i][mxid], i);
  }
  for (int j = 1; j <= m; j++) {
    int mxid = 1;
    for (int i = 2; i <= n; i++) {
      if (a[i][j] > a[mxid][j]) mxid = i;
    }
    vp.emplace_back(a[mxid][j], -j);
  }
  sort(vp.rbegin(), vp.rend());
  queue<pair<int, int> > q;
  int R = 0;
  int C = 0;
  int _R = 0;
  int _C = 0;
  for (int i = 0; i < vp.size(); i++) {
    if (i > 0) fillWeak(q, vp[i - 1].first, vp[i].first);
    if (i + 1 < vp.size() && vp[i].first == vp[i + 1].first) {
      R++;
      C++;
      _R = R;
      _C = C;
      b[R][C] = vp[i].first;
      for (int y = C - 1; y > 0; y--) q.emplace(R, y);
      for (int x = R - 1; x > 0; x--) q.emplace(x, C);
      i++;
    } else {
      if (vp[i].second > 0) {
        R++;
        for (int y = _C - 1; y > 0; y--) q.emplace(R, y);
        for (int y = _C + 1; y <= C; y++) q.emplace(R, y);
        b[R][_C] = vp[i].first;
      } else {
        C++;
        for (int x = _R - 1; x > 0; x--) q.emplace(x, C);
        for (int x = _R + 1; x <= R; x++) q.emplace(x, C);
        b[_R][C] = vp[i].first;
      }
    }
  }
  fillWeak(q, vp.back().first, 0);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cout << b[i][j] << " ";
    }
    cout << "\n";
  }
  return 0;
}
