#include <iostream>
#include <map>
#include <vector>
#include <algorithm> 
using namespace std;

map <string, int> mp;
vector <string> v;
int n, m;


bool isMore(string a, string b){
	if(mp[a] > mp[b]){
		return true; 
	}
	else{
		return false;
	}
}


bool isLonger(string a, string b){
	if(a.length() > b.length()){
		return true;
    }
	else{
		return false;
	}
}

int main(){
	
	cin.tie(NULL);
	cout.tie(NULL);
	
	cin >> n >> m;
	
	for(int i = 0; i < n; i++){
		
		string s;
		
		cin >> s;
		
		if(s.length() < m){
			continue;
		}
		
		v.push_back(s);
		
		if(mp.find(s) == mp.end()){
			mp[s] = 1;
		}
		else{
			mp[s]++;
		}
	}
	
	if(v.empty()){
		return 0;
	}
	
	// 사전순으로 배열
	sort(v.begin(), v.end());
	
	// 길이가 긴것 앞으로 배치
	sort(v.begin(), v.end(), isLonger); 
	
	// 자주 나오는 단어 앞에 배치
	sort(v.begin(), v.end(), isMore);  
	
	//중복 제거
	v.erase(unique(v.begin(), v.end()), v.end());
	
	for(int i = 0; i < v.size(); i++){
		cout << v[i] << "\n";
	}
	
	
		
}