h,w = map(int,input().split()) li = [] for i in range(h): ls = list(map(int,input().split())) li += ls li = sorted(li) for i in range(h): le = "" for j in range(w): le += str(" ") + str(li[i*w+j]) print(le[:0])