H,W=map(int,input().split()) p=sorted([int(s) for i in [0]*H for s in input().split()]) for i in range(H): print(*p[i*W:i*W+W])