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