#include "stdio.h"
int main(void) {
int num;
int length;
char str_out[100][51];
int index;
int index1;
int result[100];
int a=0;
int b=0;
int min=0;
int num2=0;
int temp;
int min_index;
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#else
#endif
scanf("%d%d",&length,&num);
num2=num;
temp=num2;
while(num>0){
scanf("%s", str_out[a]);
if(num2 == 1){
printf("%sn",str_out[a]);
return 0;
}
result[a] = 0;
for(index=0;index<length-1;index++){
if(str_out[a][index] == 'A')continue;
else{
for(index1=index+1;index1<=length-1;index1++){
if(str_out[a][index] > str_out[a][index1])result[a]++;
}
}
}
num--;
a++;
}
while(num2>0){
if(result[b]==5000)
{
b++;
continue;
}
min = result[b];
min_index = b;
for(index=0;index<temp-1;index++){
if(min > result[index+1]){
min = result[index+1];
min_index =index+1;
}
}
result[min_index] = 5000;
num2--;
printf("%sn",str_out[min_index]);
min_index = 0;
}
#ifndef ONLINE_JUDGE
fclose(stdin);
#else
#endif
return 0;