#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> g[128 * 128];
int a[128][128], b[128][128], us[128][128], used[128], mt[128 * 128];
void read() {
  int i, j;
  cin >> n >> m;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) cin >> a[i][j];
}
bool try_kuhn(int v) {
  if (used[v]) return false;
  used[v] = true;
  for (size_t i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    if (mt[to] == -1 || try_kuhn(mt[to])) {
      mt[to] = v;
      mt[v] = to;
      return true;
    }
  }
  return false;
}
void solve() {
  int i, j, l;
  for (l = 0; l < m; l++) {
    for (i = 0; i < n; i++) g[i].clear();
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (!us[i][j]) {
          g[i].push_back(a[i][j] / m - (a[i][j] % m == 0) + n);
          g[a[i][j] / m - (a[i][j] % m == 0) + n].push_back(i);
        }
      }
    }
    memset(mt, -1, sizeof(mt));
    for (int v = 0; v < n; ++v) {
      memset(used, 0, sizeof(used));
      try_kuhn(v);
    }
    for (int i = 0; i < n; ++i) {
      if (mt[i] != -1) {
        for (j = 0; j < m; j++) {
          if (a[i][j] / m - (a[i][j] % m == 0) + n == mt[i] && !us[i][j]) {
            us[i][j] = true;
            b[i][l] = a[i][j];
            break;
          }
        }
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cout << b[i][j] << " ";
    }
    cout << endl;
  }
  vector<int> h;
  for (j = 0; j < m; j++) {
    h.clear();
    for (i = 0; i < n; i++) {
      h.push_back(b[i][j]);
    }
    sort(h.begin(), h.end());
    for (i = 0; i < n; i++) {
      b[i][j] = h[i];
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cout << b[i][j] << " ";
    }
    cout << endl;
  }
}
int main() {
  read();
  solve();
  return 0;
}
