#include <bits/stdc++.h>
using namespace std;
#define LSOne(S) ((S) & -(S))
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
const int mod = 1000000007;
const int MAX = 20;
int c[MAX][MAX];
int nivel(const vi& ssy){ // devuelve la cantidad de compatibilidad que tiene un subconjunto de sayayines
int res = 0;
for(int i = 0; i<ssy.size(); ++i){
for(int j = i + 1; j < ssy.size(); ++j){
res += c[ssy[i]][ssy[j]];
}
}
return res;
}
vector<vi> subsets(vi& k, int m, int n){ // devuelve un vector con los subconjuntos de tamaño n
vector<vi> res;
for(int i = 0; i < (1 << m); ++i){
vi act;
for(int j = 0; j < m; ++j){
if((i & (1 << j))){
act.push_back(k[j]);
}
}
if(act.size() == n) res.push_back(act);
}
return res;
}
void solve(){
int n, m;
cin >> n >> m;
map<int, string> names; // nombres de los sayayines por la posicion en que esten
vi k;
for(int i = 0; i<m; ++i){
cin >> names[i];
k.push_back(i);
for(int j = 0; j<m; ++j){
cin >> c[i][j];
}
}
vector<vi> sub = subsets(k, m, n);
vi resInt;
vector<string> resString;
int maxNiv = INT_MIN;
for(const auto& i : sub){
int niv = nivel(i);
if(niv > maxNiv){
maxNiv = niv;
resInt = i;
}
}
for(const auto& i: resInt) resString.push_back(names[i]);
sort(resString.begin(), resString.end());
for(const auto& i: resString) cout << i << " ";
cout << "\n";
//int res = INT_MIN;
//vi
//cout << nivel(p);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int TC = 1;
//cin >> TC;
while(TC--) solve();
}