#include<bits/stdc++.h>
#define ri register int
using namespace std;
const int rlen = 1 << 20 | 5, inf = 0x3f3f3f3f;
char buf[rlen], *ib = buf, *ob = buf;
#define gc() (((ib == ob) && (ob = (ib = buf) + fread(buf, 1, rlen, stdin))), ib == ob ? -1 : *ib++)
inline int read() {
  static int ans;
  static char ch;
  for (ans = 0, ch = gc(); !isdigit(ch); ch = gc());
  while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = gc();
  return ans;
}
typedef long long ll;
#define pb push_back
#define rez resize
#define ppp pop_back
template <typename T> inline void exgcd(T a, T b, T &x, T &y) {
  if (!b) { x = 1, y = 0; return; }
  exgcd(b, a - a / b * b, y, x), y -= a / b * x;
}
namespace modular {
  const int mod = 998244353;
  int ret;
  inline int add(int a, int b) { return a < mod - b ? a + b : a - mod + b; }
  inline int dec(int a, int b) { return a < b ? a - b + mod : a - b; }
  inline int mul(int a, int b) { return (ll) a * b % mod; }
  inline void Add(int &a, int b) { a = a < mod - b ? a + b : a - mod + b; }
  inline void Dec(int &a, int b) { a = a < b ? a - b + mod : a - b ; }
  inline void Mul(int &a, int b) { a = (ll) a * b % mod; }
  inline int ksm(int a, int p) { for (ret = 1; p; p >>= 1, Mul(a, a)) (p & 1) && (Mul(ret, a), 1); return ret; }
  inline int fix(int x) {
    x <= -mod || x >= mod ? x %= mod : 0;
    return x < 0 ? x + mod : x;
  }
  inline int Inv(int a) {
    static int x, y;
    return exgcd(a, mod, x, y), fix(x);
  }
}  using namespace modular;
const int N = 205;
struct E { int v, c, nxt; };
int mch[N], a[N][N], n, m, id[N][N];
namespace Flow {
  int fst[N], cur[N], d[N], cnt, s, t;
  E e[N * N << 1];
  inline void init() {
    s = 0, t = n * 2 + 1, cnt = -1;
    for (ri i = s; i <= t; ++i) fst[i] = -1;
  }
  inline void addedge(int u, int v, int c) { e[++cnt] = (E) { v, c, fst[u] }, fst[u] = cnt; }
  inline void _add(int u, int v, int c) { addedge(u, v, c), addedge(v, u, 0); }
  inline bool bfs() {
    for (ri i = s; i <= t; ++i) cur[i] = fst[i], d[i] = -1;
    queue <int> q;
    d[s] = 0, q.push(s);
    while (q.size()) {
      int x = q.front();
      q.pop();
      for (ri i = fst[x]; ~i; i = e[i].nxt) if (e[i].c && d[e[i].v] == -1) {
        d[e[i].v] = d[x] + 1;
        q.push(e[i].v);
      }
    }
    return ~d[t];
  }
  inline int dfs(int x, int f) {
    if (x == t || !f) return f;
    int fl = f;
    for (ri &i = cur[x], tp, v; ~i; i = e[i].nxt) {
      if (!fl) return f;
      if (e[i].c && d[v = e[i].v] == d[x] + 1) {
        tp = dfs(v, min(fl, e[i].c));
        if (!tp) d[v] = -1;
        e[i].c -= tp, e[i ^ 1].c += tp, fl -= tp;
      } 
    }
    return f - fl;
  }
  inline void solve() {
    int tp, ss = 0;
    while (bfs()) while ((tp = dfs(s, inf)) > 0) ss += tp;
    for (ri i = 1; i <= n; ++i) for (ri j = fst[i]; ~j; j = e[j].nxt) if (!e[j].c) {
      mch[i] = e[j].v - n;
      break;
    }
  }
}
int main() {
  #ifdef ldxcaicai
  freopen("lx.in", "r", stdin);
  #endif
  n = read(), m = read();
  for (ri i = 1; i <= n; ++i) for (ri j = 1; j <= m; ++j) a[i][j] = read(), id[i][j] = (a[i][j] - 1) / m + 1;
  for (ri t = 1; t <= m; ++t) {
    Flow:: init();
    for (ri i = 1; i <= n; ++i) {
      Flow:: _add(Flow:: s, i, 1);
      for (ri j = t; j <= m; ++j) Flow:: _add(i, id[i][j] + n, 1); 
      Flow:: _add(i + n, Flow:: t, 1);
    }
    Flow:: solve();
    for (ri i = 1; i <= n; ++i) for (ri j = t; j <= m; ++j) if (id[i][j] == mch[i]) {
      if (j > t) {
        swap(id[i][t], id[i][j]);
        swap(a[i][t], a[i][j]);
      }
      break;
    }
  }
  for (ri i = 1; i <= n; ++i, cout << '\n') for (ri j = 1; j <= m; ++j) cout << a[i][j] << ' ';
  for (ri t = 1; t <= m; ++t) {
    for (ri i = 1; i <= n; ++i) for (ri j = i; j <= n; ++j) if (id[j][t] == i) {
      if (j > i) {
        swap(id[j][t], id[i][t]);
        swap(a[j][t], a[i][t]);
      }
      break;
    }
  }
  for (ri i = 1; i <= n; ++i, cout << '\n') for (ri j = 1; j <= m; ++j) cout << a[i][j] << ' ';
  return 0;
}

Measured memory_bytes: 4044