#include <bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(false);cin.tie(0);
#define setnow clock_t tStart=clock();
#define time (double)(clock() - tStart)/CLOCKS_PER_SEC;
#define setin(x) ifstream cin(x);
#define setout(x) ofstream cout(x);
typedef long long ll;
typedef long long int lli;
typedef pair < int, int> dbl;
const int maxInt = 1e9*2;
const lli maxLong = 1e18*2;
int n;
string name[1231];
int days[1231][1231];
vector <int>  eligible[1231];
bool used[1231];
int main(){
		//ifstream cin("input.in");
		int k;
		cin >> n >> k;
		for(int i=0;i<n; i++){
				cin >> name[i];
				for(int j=0; j<k; j++)
					cin >> days[i][j];
		}
		for(int r=0;r<n;r++){
			for(int j=0;j<=k-3;j++){
					if(days[r][j] < days[r][j+1] && days[r][j+1] < days[r][j+2]){
							eligible[r].push_back(j+3);
							//cout << j+3 << ' ';
					}
			}
		}
	//	cout << n << endl;
	//	for(int i=0;i<n;i++){
		//	for(unsigned j=0;j<eligible[i].size();j++)
			//	cout << eligible[i][j] << ' ';
	//		cout << endl;
	//	}
		cout << "none\n" << "none\n";
		bool ok = true;
		int day = 3;
		while(ok && day <= k){
				int certain = -1;
				int maybe = -1;
				int szMaybe = 1e9;
				for(int r = 0; r < n; r++){
						if(eligible[r].size()==1 && eligible[r][0] == day && !used[r]){
							certain = r;
							break;
						} else
						for(unsigned j=0;j<eligible[r].size();j++){
								if(eligible[r][j] == day && !used[r])
									if(eligible[r].size() < (unsigned)szMaybe && !used[r]){
											szMaybe = eligible[r].size();
											maybe = r;
									}
						}
				}
				if(certain != -1){
					cout << name[certain] << endl;
					used[certain] = 1;
				}
				else if(maybe != -1) { 
					cout << name[maybe] << endl;
					used[maybe]  = 1;
				} else ok = false;
				day++;
		}
		return(0);
}