// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-6
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
using namespace std;
// mylittledoge
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int N,M;
cin >> N >> M;
map<string,int> L,R;
vector<string> S(N);
vector< pair<string,string> > V(N);
for(int i =0; i < N; i++) {
string s;
cin >> s;
S[i] =s;
for(uint j =0; j <= s.length(); j++) if(j == s.length() || s[j] == '.') {
V[i].ff =s.substr(0,j);
if(j != s.length()) V[i].ss =s.substr(j+1,s.length()-j);
break;}
L[V[i].ff] =0;
R[V[i].ss] =0;}
int l =0, r =0;
ALL_THE(L,it) it->ss =l++;
ALL_THE(R,it) it->ss =r++;
vector< set< pair<int,int> > > Gl(L.size());
vector< set< pair<int,int> > > Gr(R.size());
for(int i =0; i < N; i++) {
Gl[L[V[i].ff]].insert(make_pair(R[V[i].ss],i));
Gr[R[V[i].ss]].insert(make_pair(L[V[i].ff],i));}
set<int> ans;
for(int i =0; i < N; i++) ans.insert(i);
for(int k =0; k < M; k++) {
vector< set< pair<int,int> > > Gl0 =Gl, Gr0 =Gr;
if(k%2 != 0) {
for(int i =0; i < l; i++) if(Gl0[i].size() == 1) {
int x =Gl[i].begin()->ss;
int a =L[V[x].ff], b =R[V[x].ss];
Gl[a].erase(make_pair(b,x));
Gr[b].erase(make_pair(a,x));
ans.erase(x);}
}
else {
for(int i =0; i < r; i++) if(Gr0[i].size() == 1) {
int x =Gr[i].begin()->ss;
int a =L[V[x].ff], b =R[V[x].ss];
Gl[a].erase(make_pair(b,x));
Gr[b].erase(make_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