H, W = [int(i) for i in input().strip().split(' ')] A = sorted(' '.join([input().strip() for _ in range(H)]).split(' ')) print('\n'.join([' '.join(A[i*W:i*W+W]) for i in range(len(A) // W)]))