#include <bits/stdc++.h>
const long double eps = 1e-9;
const long double pi = acos(-1.0);
using namespace std;
const int N = 300;
int a[N][N], used[N * N];
int n, m;
bool check(vector<int> r, vector<int> c) {
  vector<int> check_r, check_c;
  for (int i = 1; i <= n; i++) {
    int mx = 0;
    for (int j = 1; j <= m; j++) mx = max(mx, a[i][j]);
    check_r.push_back(mx);
  }
  for (int j = 1; j <= m; j++) {
    int mx = 0;
    for (int i = 1; i <= n; i++) mx = max(mx, a[i][j]);
    check_c.push_back(mx);
  }
  sort(check_r.begin(), check_r.end());
  sort(check_c.begin(), check_c.end());
  return (check_r == r && check_c == c);
}
void solve() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  vector<int> r, c;
  for (int i = 1; i <= n; i++) {
    int mx = 0;
    for (int j = 1; j <= m; j++) mx = max(mx, a[i][j]);
    r.push_back(mx);
  }
  for (int j = 1; j <= m; j++) {
    int mx = 0;
    for (int i = 1; i <= n; i++) mx = max(mx, a[i][j]);
    c.push_back(mx);
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) a[i][j] = 0;
  sort(r.begin(), r.end());
  sort(c.begin(), c.end());
  vector<int> last_c, last_r;
  last_r = r, last_c = c;
  int posx, posy;
  posx = posy = 0;
  while (r.size() > 0 || c.size() > 0) {
    if (r.size() > 0 && c.size() > 0) {
      int R = r.back();
      int C = c.back();
      if (R == C) {
        posx++, posy++;
        a[posx][posy] = R;
        r.pop_back();
        c.pop_back();
        used[R] = used[C] = 1;
        continue;
      }
      if (C > R) {
        posy++;
        c.pop_back();
        a[posx][posy] = C;
        used[C] = 1;
      }
      if (R > C) {
        posx++;
        r.pop_back();
        a[posx][posy] = R;
        used[R] = 1;
      }
    } else if (r.size() > 0) {
      int R = r.back();
      posx++;
      r.pop_back();
      a[posx][posy] = R;
      used[R] = 1;
    } else {
      int C = c.back();
      posy++;
      c.pop_back();
      a[posx][posy] = C;
      used[C] = 1;
    }
  }
  vector<int> not_used;
  for (int i = 1; i <= n * m; i++)
    if (!used[i]) not_used.push_back(i);
  reverse(not_used.begin(), not_used.end());
  for (int i = n; i >= 1; i--) {
    for (int j = m; j >= 1; j--) {
      if (used[a[i][j]]) {
        for (int q = 1; q < i; q++)
          if (a[q][j] == 0) a[q][j] = not_used.back(), not_used.pop_back();
        for (int q = 1; q < j; q++)
          if (a[i][q] == 0) a[i][q] = not_used.back(), not_used.pop_back();
      }
    }
  }
  if (!check(last_r, last_c)) {
    cout << -1 << endl;
    return;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
}
int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(10);
  int step;
  step = 1;
  for (int i = 1; i <= step; i++) {
    solve();
  }
}
