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