1 #include <vector>
2 #include <list>
3 #include <map>
4 #include <set>
5 #include <deque>
6 #include <queue>
7 #include <stack>
8 #include <bitset>
9 #include <algorithm>
10 #include <functional>
11 #include <numeric>
12 #include <utility>
13 #include <sstream>
14 #include <iostream>
15 #include <iomanip>
16 #include <cstdio>
17 #include <cmath>
18 #include <cstdlib>
19 #include <cctype>
20 #include <string>
21 #include <cstring>
22 #include <cstdio>
23 #include <cmath>
24 #include <cstdlib>
25 #include <ctime>
26
27 using namespace std;
28
29 #define M 30
30 #define W 10
31
32 struct Node
33 {
34 int b[W];
35 int head;
36 int ind;
37 };
38
39 Node box[M];
40
41 int cmp(const void *a,const void *b)
42 {
43 return (*(Node*)a).head-(*(Node*)b).head;
44 }
45
46 bool Isok(int a[],int b[],int m)
47 {
48 for (int i=0;i<m;i++)
49 {
50 if (a[i]>=b[i]) return false;
51 }
52 return true;
53 }
54 int main()
55 {
56 int n,m;
57 int p[M],q[M];
58 while (scanf("%d%d",&n,&m)!=-1)
59 {
60 for (int i=0;i<n;i++)
61 {
62 for (int j=0;j<m;j++)
63 {
64 scanf("%d",&box[i].b[j]);
65 }
66 sort(box[i].b,box[i].b+m);
67 box[i].head=box[i].b[0];
68 box[i].ind=i+1;
69 }
70 qsort(box,n,sizeof(box[0]),cmp);
71
72 p[0]=1;
73 q[0]=-1;
74 for (int i=1;i<n;i++)
75 {
76 int Max=0,t;
77 for (int j=i-1;j>=0;j--)
78 {
79 if (Isok(box[j].b,box[i].b,m))
80 {
81 if (p[j]>Max)
82 {
83 Max=p[j];
84 t=j;
85 }
86 }
87 }
88 if (Max)
89 {
90 p[i]=p[t]+1;
91 q[i]=t;
92 }
93 else
94 {
95 p[i]=1;
96 q[i]=-1;
97 }
98 }
99
100 vector<int> vi;
101 int Mi=0,Mii=0;
102 for (int i=0;i<n;i++)
103 if (Mii<p[i])
104 {
105 Mi=i;
106 Mii=p[i];
107 }
108 while (q[Mi]!=-1)
109 {
110 vi.push_back(box[Mi].ind);
111 Mi=q[Mi];
112 }
113 vi.push_back(box[Mi].ind);
114 printf("%d\n%d",Mii,vi[vi.size()-1]);
115 for (int i=vi.size()-2;i>=0;i--)
116 printf(" %d",vi[i]);
117 printf("\n");
118 }
119 return 0;
120 }
121