H,W=map(int,input().split()) A=[] for _ in range(H): A+=list(map(int,input().split())) A.sort() L=0 for _ in range(H): print(*A[L:L+W]) L+=W