import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int m = input.nextInt();//科目数
Stu[] stu = new Stu[n];
for(int i=0;i<n;i++){
stu[i] = new Stu();
stu[i].name = input.next();
for(int j=0;j<m;j++){
stu[i].sbj[j] = input.nextInt();
stu[i].sum+=stu[i].sbj[j];
}
}
//冒泡排序
for(int i=0;i<n;i++){
for(int j=0;j<n-i-1;j++){
if(cmp(stu[j],stu[j+1],m)){
Stu a = stu[j];
stu[j] = stu[j+1];
stu [j+1] = a;
}
}
}
for(int i=n-1;i>=0;i--){
System.out.print(stu[i].name+" ");
}
}
public static boolean cmp(Stu a,Stu b,int m){
if(a.sum!=b.sum){
return a.sum>b.sum;
}
for(int i=0;i<m;i++){
if(a.sbj[i]!=b.sbj[i]){
return a.sbj[i]>b.sbj[i];
}
}
return false;
}
public static class Stu {
String name = null;
int sbj[] = new int[110];
int sum=0;
}
}