#include <bits/stdc++.h>
using namespace ::std;
const long long maxn = 260;
const long long inf = 1e9 + 900;
int c[maxn][maxn];
int I[maxn * maxn];
int J[maxn * maxn];
int ans[maxn * 2][maxn * 2];
int l[maxn * 2];
int r[maxn * 2];
int o[maxn * 2];
int s = maxn * 2;
int t = 0;
int ss = maxn * 2;
int tt = 0;
void put(int i, int j, int v) {
  ans[i][j] = v;
  if (o[j] == 0) {
    o[j] = i;
  } else {
    o[j] = max(o[j], i);
  }
  if (l[i] == 0 && r[i] == 0) {
    l[i] = j;
    r[i] = j;
  } else {
    l[i] = min(l[i], j);
    r[i] = max(r[i], j);
  }
  s = min(s, i);
  t = max(t, i);
  ss = min(ss, j);
  tt = max(tt, j);
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> c[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    int mx = 0;
    for (int j = 0; j < m; j++) {
      mx = max(mx, c[i][j]);
    }
    I[mx] = 1;
  }
  for (int j = 0; j < m; j++) {
    int mx = 0;
    for (int i = 0; i < n; i++) {
      mx = max(mx, c[i][j]);
    }
    J[mx] = 1;
  }
  put(maxn, maxn, n * m);
  for (int i = n * m - 1; i >= 1; i--) {
    if (I[i] && J[i]) {
      put(s - 1, l[s] - 1, i);
    } else if (I[i]) {
      put(maxn, r[maxn] + 1, i);
    } else if (J[i]) {
      put(t + 1, maxn, i);
    } else {
      bool ok = 0;
      for (int j = maxn; j <= t; j++) {
        if (r[j] < tt) {
          ok = 1;
          put(j, r[j] + 1, i);
          break;
        }
      }
      if (ok) continue;
      for (int j = maxn - 1; j >= s; j--) {
        if (r[j] < tt) {
          ok = 1;
          put(j, r[j] + 1, i);
          break;
        }
      }
      if (ok) continue;
      for (int j = maxn - 1; j >= ss; j--) {
        if (o[j] < t) {
          put(o[j] + 1, j, i);
          ok = 1;
          break;
        }
      }
      if (ok) continue;
      if (!ok) {
        cout << -1;
        return 0;
      }
    }
  }
  for (int i = ss; i <= tt; i++) {
    for (int j = s; j <= t; j++) {
      cout << ans[j][i] << ' ';
    }
    cout << endl;
  }
}
