#include <bits/stdc++.h>
using namespace std;
void finish() {
  printf("-1\n");
  exit(0);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> row(n), col(m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int first;
      scanf("%d", &first);
      row[i] = max(row[i], first);
      col[j] = max(col[j], first);
    }
  sort(row.begin(), row.end());
  sort(col.begin(), col.end());
  reverse(row.begin(), row.end());
  reverse(col.begin(), col.end());
  int i = 0, j = 0;
  vector<vector<int> > ans(n, vector<int>(m, -1));
  vector<int> bef(n), aft(n);
  for (int xxx = 0; xxx < n * m; xxx++) {
    int num = n * m - xxx;
    bool first = (i < n && row[i] == num), second = (j < m && col[j] == num);
    if (first && second) {
      bef[i] = aft[i] = j;
      ans[i++][j++] = num;
    } else if (first) {
      if (j == 0) finish();
      bef[i] = aft[i] = j - 1;
      ans[i++][j - 1] = num;
    } else if (second) {
      if (i == 0) finish();
      ans[i - 1][j++] = num;
    } else {
      bool found = 0;
      for (int k = 0; k < i; k++) {
        if (1) {
          int &r = aft[k];
          while (r < j && ans[k][r] != -1) r++;
          if (r < j && ans[k][r] == -1 && (k == n - 1 || ans[k + 1][r] != -1)) {
            ans[k][r] = num;
            found = 1;
            r++;
            break;
          }
        }
        if (1) {
          int &r = bef[k];
          while (r >= 0 && ans[k][r] != -1) r--;
          if (r >= 0 && ans[k][r] == -1 && (k == 0 || ans[k - 1][r] != -1)) {
            ans[k][r] = num;
            r--;
            found = 1;
            break;
          }
        }
      }
      if (!found) finish();
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) printf("%d ", ans[i][j]);
    printf("\n");
  }
  return 0;
}
