Problem: We have a grid with N rows and M columns of squares. Each integer from 1 to NM is written in this grid once. The number written in the square at the i-th row from the top and the j-th column from the left is A_{ij}.

You need to rearrange these numbers as follows:

1. First, for each of the N rows, rearrange the numbers written in it as you like.
2. Second, for each of the M columns, rearrange the numbers written in it as you like.
3. Finally, for each of the N rows, rearrange the numbers written in it as you like.



After rearranging the numbers, you want the number written in the square at the i-th row from the top and the j-th column from the left to be M\times (i-1)+j. Construct one such way to rearrange the numbers. The constraints guarantee that it is always possible to achieve the objective.

Constraints

* 1 \leq N,M \leq 100
* 1 \leq A_{ij} \leq NM
* A_{ij} are distinct.

Input

Input is given from Standard Input in the following format:


N M
A_{11} A_{12} ... A_{1M}
:
A_{N1} A_{N2} ... A_{NM}


Output

Print one way to rearrange the numbers in the following format:


B_{11} B_{12} ... B_{1M}
:
B_{N1} B_{N2} ... B_{NM}
C_{11} C_{12} ... C_{1M}
:
C_{N1} C_{N2} ... C_{NM}


Here B_{ij} is the number written in the square at the i-th row from the top and the j-th column from the left after Step 1, and C_{ij} is the number written in that square after Step 2.

Examples

Input

3 2
2 6
4 3
1 5


Output

2 6
4 3
5 1
2 1
4 3
5 6


Input

3 4
1 4 7 10
2 5 8 11
3 6 9 12


Output

1 4 7 10
5 8 11 2
9 12 3 6
1 4 3 2
5 8 7 6
9 12 11 10

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=205,MAXM=5e4+5;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
struct Edge{int to,next,w;}edges[MAXM];
int head[MAXN],cur[MAXN],d[MAXN],S,T,cnt;
inline void Init(){memset(head,0,sizeof(head)),cnt=1;}
inline void add(int x,int y,int w){
	edges[++cnt]=(Edge){y,head[x],w},head[x]=cnt;
	edges[++cnt]=(Edge){x,head[y],0},head[y]=cnt;
}
inline bool bfs(){
	queue<int>q;q.push(S),memset(d,0,sizeof(d)),memcpy(cur,head,sizeof(head)),d[S]=1;
	for(int x;!q.empty();q.pop()){
		x=q.front();
		for(int i=head[x],y;i;i=edges[i].next)	
			if(edges[i].w&&!d[y=edges[i].to])d[y]=d[x]+1,q.push(y);
	}return d[T];
}
int dfs(int x,int dist){
	if(x==T||!dist)return dist;int z=0;
	for(int&i=cur[x],y,k;i;i=edges[i].next)if(edges[i].w&&d[y=edges[i].to]==d[x]+1){
		k=dfs(y,min(dist,edges[i].w)),edges[i].w-=k,edges[i^1].w+=k,z+=k,dist-=k;
		if(!dist)break;
	}return z;
}
inline int Dinic(){int ans=0;for(;bfs();)ans+=dfs(S,1e9);return ans;}
int n,m,A[MAXN][MAXN],B[MAXN][MAXN],C[MAXN][MAXN],O[MAXN];queue<int>Q[MAXN][MAXN];
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),m=read(),S=0,T=2*n+1;
	Rep(i,1,n)Rep(j,1,m)A[i][j]=read(),Q[i][(A[i][j]-1)/m+1].push(A[i][j]);
	Rep(o,1,m){
		Init();Rep(i,1,n)add(S,i,1),add(i+n,T,1);
		Rep(i,1,n)Rep(j,1,n)if(Q[i][j].size())add(i,j+n,1);
		if(Dinic()!=n)return puts("-1"),0;
		Rep(i,1,n)for(int j=head[i];j;j=edges[j].next)if(!edges[j].w)
			B[i][o]=Q[i][edges[j].to-n].front(),Q[i][edges[j].to-n].pop();
	}Rep(i,1,n){Rep(j,1,m)cout<<B[i][j]<<" ";cout<<"\n";}
	Rep(i,1,m){Rep(j,1,n)O[j]=B[j][i];sort(O+1,O+n+1);Rep(j,1,n)C[j][i]=O[j];}
	Rep(i,1,n){Rep(j,1,m)cout<<C[i][j]<<" ";cout<<"\n";}
	return 0;
}