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