Programming Problem #24
"Nesting Boxes"

Consider an N-dimensional 'box' given by its dimensions (d_1,...,d_n). For example, in two dimensions (2,3) might denote a box two units wide and three units long; in three dimensions, (5,1,6) might denote a box five units wide, one unit long, and six units high.

Box D=(d_1,...,d_n) is said to nest inside box E=(e_1,...,e_n) if there is some way to rearrange the d_i such that each dimension in D is less than the corresponding dimension in E. For example, (7,1,10) nests inside (3,15,8) since (7,1,10) can be rearranged to form (1,10,7), and 1<3, 10<15, and 7<8. A nesting sequence is a sequence D_1,...,D_k of boxes in which D_1 nests inside D_2, D_2 nests inside D_3, etc.

The input consists of one or more problem descriptions. Each description begins with a line containing two positive integers K and N, where K is the number of boxes and N is the number of dimensions. After this line will follow K lines, each of which gives the dimensions for an N-dimensional box. The boxes are implicitly numbered from 1 to K. All of the dimensions will be nonnegative integers. For each problem description output a line containing a nesting sequence of maximal length. The boxes in the sequence are identified by their numbers.

Input must be read from the file "prob24.in", and output must be written to the file "prob24.out". All output to the screen will be ignored.


Example Input

<BOF>
5 2
3 7
8 10
5 2
9 11
21 18
8 6
5 2 20 1 30 10
23 15 7 9 11 3
40 50 34 24 14 4
9 10 11 12 13 14
31 4 18 8 27 17
44 32 13 19 41 19
1 2 3 4 5 6
80 37 47 18 21 9
<EOF>

Example Output

3 1 2 4 5
7 2 5 6

A version of this problem originally appeared in the 1990 Duke Internet contest.

Dr. Eric Shade