复杂的排序
int acm[1005][3];
int num[1005][4];
int qu[1005];
int judge(int a,int b,int type)
{
    
int i;
    
int ans=0;
    
if(type==0)
    
{
        
for(i=0;i<4;i++)
        
{
            
if(num[qu[a]][i]>num[qu[b]][i]){ans=1;break;}
            
if(num[qu[a]][i]<num[qu[b]][i]){ans=-1;break;}
        }

    }

    
else
    
{
        
for(i=0;i<3;i++)
        
{
            
if(i==0)
            
{
                
if(acm[qu[a]][i]>acm[qu[b]][i]){ans=1;break;}
                
if(acm[qu[a]][i]<acm[qu[b]][i]){ans=-1;break;}
            }

            
else
            
{
                
if(acm[qu[a]][i]>acm[qu[b]][i]){ans=-1;break;}
                
if(acm[qu[a]][i]<acm[qu[b]][i]){ans=1;break;}
            }

        }

    }

    
return ans;
}


void swap(int a,int b)
{
    
int t;
    t
=qu[a];
    qu[a]
=qu[b];
    qu[b]
=t;
}


int partion(int low,int high,int p,int type)
{
    
while(low<=high)
    
{
        
if(low<p)
        
{
            
if(judge(low,p,type)>0){swap(low,p);p=low;}
            low
++;
        }

        
else
        
{
            
if(high>p)
            
{
                
if(judge(high,p,type)<0){swap(high,p);p=high;}
            }

            high
--;
        }

    }

    
return p;
}


void qsort(int left,int right,int type)
{
    
int middle;
    
if(left<right)
    
{
        middle
=(left+right)/2;
        middle
=partion(left,right,middle,type);
        qsort(left,middle
-1,type);
        qsort(middle
+1,right,type);
    }

}

 
int main()
{
    
int c,n;
    
int time,flag;
    
int i;
    
while(scanf("%d%d",&c,&n)!=EOF)
    
{
        
for(i=0;i<n;i++)
        
{
            scanf(
"%d%d%d%d",&num[i][0],&num[i][1],&num[i][2],&num[i][3]);
            num[i][
0]--;
            qu[i]
=i;
        }


        qsort(
0,n-1,0);

        
for(i=0;i<c;i++){acm[i][0]=acm[i][1]=0;acm[i][2]=i;}
        
        flag
=num[qu[0]][3];
        
if(flag)time=num[qu[0]][2];
        
else time=1200;

        
for(i=1;i<n;i++)
        
{
            
if(num[qu[i]][0]==num[qu[i-1]][0]&&num[qu[i]][1]==num[qu[i-1]][1])
            
{
                
if(flag==0)
                
{
                    
if(num[qu[i]][3]==0)time+=1200;
                    
else
                    
{
                        time
+=num[qu[i]][2];
                        flag
=1;
                    }

                }

            }

            
else
            
{
                acm[num[qu[i
-1]][0]][0]+=flag*1;
                acm[num[qu[i
-1]][0]][1]+=time*flag;
                flag
=num[qu[i]][3];
                
if(flag)time=num[qu[i]][2];
                
else time=1200;
            }

        }


        acm[num[qu[i
-1]][0]][0]+=flag*1;
        acm[num[qu[i
-1]][0]][1]+=time*flag;

        
for(i=0;i<c;i++)qu[i]=i;

        qsort(
0,c-1,1);
        
for(i=c-1;i>=0;i--)
        
{
            printf(
"%d ",acm[qu[i]][2]+1);
        }

        printf(
"\n");
    }

    
return 0;
}