#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
bool ckmin(T &a, U b) {
  return b < a ? a = b, true : false;
}
template <typename T, typename U>
bool ckmax(T &a, U b) {
  return b > a ? a = b, true : false;
}
int n, m;
set<int, greater<int>> rem;
vector<int> x, y, ax, ay;
vector<vector<int>> v, a;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  x.assign(n, 0);
  y.assign(m, 0);
  ax.assign(n, 0);
  ay.assign(m, 0);
  v.assign(n, vector<int>(m, 0));
  a.assign(n, vector<int>(m, 0));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> v[i][j];
    }
  }
  for (int i = 0; i < n * m; ++i) {
    rem.insert(i + 1);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      ckmax(x[i], v[i][j]);
    }
  }
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      ckmax(y[i], v[j][i]);
    }
  }
  set<int, greater<int>> xx, yy;
  for (auto i : x) xx.insert(i);
  for (auto i : y) yy.insert(i);
  for (auto i : x) {
    if (rem.find(i) != rem.end()) rem.erase(i);
  }
  for (auto j : y) {
    if (rem.find(j) != rem.end()) rem.erase(j);
  }
  int r = -1, c = -1;
  while ((int)(xx).size() && (int)(yy).size()) {
    auto it1 = xx.begin(), it2 = yy.begin();
    if (*it1 == *it2) {
      r++, c++;
      a[r][c] = *it1;
      xx.erase(it1);
      yy.erase(it2);
    } else if (*it1 > *it2) {
      r++;
      a[r][c] = *it1;
      xx.erase(it1);
    } else {
      c++;
      a[r][c] = *it2;
      yy.erase(it2);
    }
  }
  while ((int)(yy).size()) {
    c++;
    a[r][c] = *yy.begin();
    yy.erase(yy.begin());
  }
  while ((int)(xx).size()) {
    r++;
    a[r][c] = *xx.begin();
    xx.erase(xx.begin());
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      ckmax(ax[i], a[i][j]);
    }
  }
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      ckmax(ay[i], a[j][i]);
    }
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (!a[i][j]) continue;
      queue<pair<int, int>> q;
      q.push(make_pair(i - 1, 0));
      q.push(make_pair(j - 1, 1));
      while ((int)(q).size()) {
        pair<int, int> x = q.front();
        q.pop();
        auto it = rem.lower_bound(a[i][j]);
        if (x.second) {
          if (x.first < 0) continue;
          if (!a[i][x.first]) {
            assert(it != rem.end());
            a[i][x.first] = *it;
            rem.erase(it);
          }
          q.push(make_pair(x.first - 1, 1));
        } else {
          if (x.first < 0) continue;
          if (!a[x.first][j]) {
            assert(it != rem.end());
            a[x.first][j] = *it;
            rem.erase(it);
          }
          q.push(make_pair(x.first - 1, 0));
        }
      }
    }
  }
  sort(ay.begin(), ay.end());
  sort(ax.begin(), ax.end());
  if (ay == y && ax == x) {
    for (auto i : a) {
      for (auto j : i) {
        cout << j << " ";
      }
      cout << "\n";
    }
  } else
    cout << "-1";
  return 0;
}
