#include <bits/stdc++.h>
using namespace std;
#define inf 10000000000000LL
#define iinf 2000000000
#define linf 1000000000000000000LL
#define ulinf 10000000000000000000ull
#define MOD1 1000000007LL
#define mpr make_pair
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef unsigned short US;
typedef pair < int , int > pii;
clock_t __stt;
inline void TStart(){__stt=clock();}
inline void TReport(){printf("\nTaken Time : %.3lf sec\n",(double)(clock()-__stt)/CLOCKS_PER_SEC);}
template < typename T > T MIN(T a,T b){return a<b?a:b;}
template < typename T > T MAX(T a,T b){return a>b?a:b;}
template < typename T > T ABS(T a){return a>0?a:(-a);}
template < typename T > void UMIN(T &a,T b){if(b<a) a=b;}
template < typename T > void UMAX(T &a,T b){if(b>a) a=b;}
const int S=202,T=203;
namespace flow{
	struct edge{
		int v,r;
		LL f;
		void set(int V,int R,LL F){
			v=V;r=R;f=F;
		}
	};
	vector < edge > adj[205];
	int cur[205],dis[205];
	void init(){
		int i;
		for(i=0;i<205;++i) adj[i].clear();
	}
	void addedge(int u,int v,LL f){
		edge T;
		T.set(v,(int)adj[v].size(),f);
		adj[u].push_back(T);
		T.set(u,(int)adj[u].size()-1,0LL);
		adj[v].push_back(T);
	}
	void bfs(){
		queue < int > Q;
		Q.push(S);
		dis[S]=0;
		while(!Q.empty()){
			int i,cv=Q.front();
			Q.pop();
			for(i=0;i<(int)adj[cv].size();++i){
				if(adj[cv][i].f>0LL && dis[adj[cv][i].v]==-1){
					dis[adj[cv][i].v]=dis[cv]+1;
					Q.push(adj[cv][i].v);
				} 
			}
		}
	}
	LL dfs(int ver,LL cap){
		if(ver==T) return cap;
		int i;
		for(i=cur[ver];i<(int)adj[ver].size();++i){
			cur[ver]=i;
			edge &E=adj[ver][i];
			if(E.f>0LL && dis[E.v]>dis[ver]){
				LL ret=dfs(E.v,MIN(cap,E.f));
				if(ret>0LL){
					E.f-=ret;
					adj[E.v][E.r].f+=ret;
					return ret;
				}
			}
		}
		return 0LL;
	}
	LL maxflow(){
		LL ret=0LL,dlt;
		while(1){
			memset(dis,-1,sizeof(dis));
			memset(cur,0,sizeof(cur));
			bfs();
			if(dis[T]==-1) return ret;
			dlt=1LL;
			while(dlt){
				dlt=dfs(S,inf*2LL);
				ret+=dlt;
			}
		}
	}
};
int n,m,a[105][105],col[105][105],fs[105][105];
int b[105][105],c[105][105];
bool used[105][105];
int main(){
	int i,j,k;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;++i){
		for(j=0;j<m;++j){
			scanf("%d",&a[i][j]);
			--a[i][j];
		}
	}
	for(i=0;i<m;++i){
		flow::init();
		memset(fs,-1,sizeof(fs));
		for(j=0;j<n;++j){
			for(k=0;k<m;++k){
				if(!used[j][k]) fs[j][a[j][k]/m]=k;
			}
			for(k=0;k<n;++k){
				if(fs[j][k]!=-1) flow::addedge(k,j+n,1ll); 
			}
		}
		for(j=0;j<n;++j){
			flow::addedge(S,j,1ll);
			flow::addedge(j+n,T,1ll);
		}
		flow::maxflow();
		using namespace flow;
		for(j=0;j<n;++j){
			for(k=0;k<(int)adj[j].size();++k){
				edge &E=adj[j][k];
				if(E.v>=n && E.v<n+n && !(E.f)){
					assert(fs[E.v-n][j]!=-1);
					col[E.v-n][fs[E.v-n][j]]=i;
					used[E.v-n][fs[E.v-n][j]]=1;
				}
			}
		}
	}
	for(i=0;i<n;++i){
		for(j=0;j<m;++j){
			b[i][col[i][j]]=a[i][j];
			c[col[i][j]][i]=a[i][j];
		}
	}
	for(j=0;j<m;++j){
		sort(c[j],c[j]+n);
	}
	for(i=0;i<n;++i){
		for(j=0;j<m;++j){
			printf("%d%c",b[i][j]+1,j==m-1?'\n':' ');
		}
	}
	for(i=0;i<n;++i){
		for(j=0;j<m;++j){
			printf("%d%c",c[j][i]+1,j==m-1?'\n':' ');
		}
	}
	return 0;
}

Measured memory_bytes: 1024