
[cpp]
#include<iostream>
#include<string.h>
using namespace std;
unsigned long box[30][10]; //stores the size of each box
int arrbox[10]; //the i'th smallest box is of index arrbox comparing the first dimension after the dimenstions are sorted
int n,dim;
int chain[30][2]; //chain[1] is the length of the longest chain starting from the i'th smallest box
//chain[0] is the next box if going along the longest chain
void bubble(int k){
//sorts the k'th box's dimensions in descending order
for(int i=0;i<dim-1;i++)
for(int j=0;j<dim-1-i;j++)
if(box[k][j+1]>box[k][j]){
unsigned long temp=box[k][j+1];
box[k][j+1]=box[k][j],box[k][j]=temp;
}
}
int larger(int i,int k){
//judge whether the k'th smallest box can be fixed in the i'th smallest box
for(int j=0;j<dim;j++)
if(box[arrbox][j]<=box[arrbox[k]][j])
return 0;
return 1;
}
void getchain(int k){
//starting from the k'th smallest box, find chain[k][0](the next box) and chain[k][1](the longest length starting from it)
if(chain[k][1]!=-1)
return;
chain[k][1]=1;
for(int i=k+1;i<n;i++)
if(larger(i,k)){
getchain(i);
if(chain[1]+1>chain[k][1])
chain[k][1]=chain[1]+1,chain[k][0]=i;
}
}
void arrangebox(){
//sort the boxes in ascending order
int i,j;
for(i=0;i<n;i++)
arrbox=i;
for(i=0;i<n-1;i++)
for(j=0;j<n-i-1;j++)
if(box[arrbox[j+1]][0]<box[arrbox[j]][0]){
int temp=arrbox[j+1];
arrbox[j+1]=arrbox[j],arrbox[j]=temp;
}
}
void main(){
int i;
while(cin>>n>>dim){
memset(chain,-1,sizeof(chain));
for(i=0;i<n;i++)
for(int j=0;j<dim;j++)
cin>>box[j];
for(i=0;i<n;i++)
bubble(i);
arrangebox();
for(i=0;i<n;i++)
getchain(i);
if(n>0){
int start=0;
for(i=1;i<n;i++)
if(chain[1]>chain[start][1])
start=i;
cout<<chain[start][1]<<endl;
while(chain[start][0]!=-1){
cout<<arrbox[start]+1<<' ';
start=chain[start][0];
}
cout<<arrbox[start]+1<<endl;
}
else
cout<<0<<endl;
}
}[/cpp]