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