h, w = map(int, input().split()) A = [] for i in range(h): A += list(map(int, input().split())) A.sort() for i in range(h): print(*A[i*w:(i+1)*w])