#include #include #include #include #include #include using namespace std; typedef map rem_t; struct group { int m; vector votes; int vote(const rem_t &rem) { for(int i = 0; i < votes.size(); i++) if(rem.find(votes[i]) != rem.end()) { // printf("%d votes for %d\n", m, votes[i]); return votes[i]; } cerr << "AARGH!\n"; return 0; } }; void run() { int g,n; cin >> g >> n; if(g == 0 && n == 0) exit(0); rem_t candidates; for(int i = 1; i <= n; i++) candidates.insert(make_pair(i,0)); vector groups; for(int i = 0; i < g; i++) { group gr; cin >> gr.m; for(int j = 0; j < n; j++) { int x; cin >> x; gr.votes.push_back(x); } // printf("m=%d\n", gr.m); groups.push_back(gr); } while(candidates.size() > 1) { for(rem_t::iterator it = candidates.begin(); it != candidates.end(); ++it) it->second = 0; for(int i = 0; i < g; i++) candidates[groups[i].vote(candidates)] += groups[i].m; int worst = 10000000; int loser = 0; for(rem_t::iterator it = candidates.begin(); it != candidates.end(); ++it) { if(it->second <= worst) { worst = it->second; loser = it->first; } } // printf("%d loses\n", loser); candidates.erase(loser); } cout << candidates.begin()->first << endl; } int main() { while(1) run(); }