H,W = map(int,input().split()) num_list = [] for i in range(H): num_list += list(map(int,input().split())) num_list.sort() NEW_list=[] for i in range(H): new_list=[] j = 0 while j < W: s = num_list[0] new_list.append(str(s)) num_list.remove(s) j += 1 NEW_list.append(new_list) for i in NEW_list: print(' '.join(i))