The cows celebrated another banner month for record milk production and thus have each earned a special treat. They completely fill a w \times h rectangle formation awaiting their treat.
Each cow has a unique figure of merit F_{rc} (1 \le F_{rc} \le 1000000) which denotes her overall milk production performance. Farmer John thinks it is only fair to prioritize the treats handed out, rewarding the highest producing cows first. He plans to traverse the rectangular formation one row at a time, starting at the beginning of row and giving out all row 's treats before he starts on row using the same method.
He has asked the cows to reorganize themselves so that the cows with better production are rewarded first. The cows, though, are not so very good at organization. They can either swap a pair of rows or swap a pair of columns of their formation. FJ has asked them to do the best they can by moving the best cow to the upper left corner (row , column ), the next best cow to row , column (if possible), and so on. Of course, the cows can not fully sort themselves, but they can do their best by following this heuristic:
determine the order of FJ's treat awards:

find the highest rated cow; swap rows and columns until she is at row , column ; never move her again
Then execute this rule until as many cows are placed as possible:
Find the next highest rated cow. Swap rows and columns (without moving any higher-rated cow) to move her to the best possible spot that is still available (e.g., row , column if it's available or row , column if no slots can be achieved in row .
By way of example, consider this set of 3 \times 4 cows:

The cow with is clearly the highest-rated and belongs in the upper left corner. Swap rows and then swap columns and (or do it the other way around - the answer is the same):

The cow with should be rewarded as soon as possible after the highest-rated cow. She is current in slot (, ), the last slot to be rewarded. At this point, it's too late to swap her into the first row or even the first column. Thus, she needs to move to (, ) by swapping columns and then swapping rows and :

The cow with is rewarded directly after the cow with . The cow is already rewarded. The cow with is awarded just after the cow with . The cow with is rewarded directly after the cow with . The cow with is already rewarded. The cow with would best move to row , column but the rows and are frozen as are all the columns. Thus, cows , and do not move, and the second diagram above is the "best the cows can do".
Implement this algorithm for other rectangular arrays of cows.
First line contains two space-separated integers and (1 \le w \le 25, 1 \le h \le 25). Each of the next lines contains space-separated integers F_{ic} (1 \le c \le w).
Print lines. Each line contains space-separated integers representing the row of cows in the cows' final formation.
Example 1