H, W = map(int, input().split()) A = [] for i in range(H): A.extend(list(map(int, input().split()))) sorted_A = sorted(A) for i,j in enumerate(sorted_A): print(j,end=' ') if (i+1)%W == 0 :print()