#include <iostream>
using namespace std;
int main(){
	int n,q;
	while(cin>>n>>q){
		if(!n&&!q)break;
		int count[101]={0},ans=0,max=0;
		while(n--){
			int m,date;
			cin>>m;
			while(m--){
				cin>>date;
				count[date]++;
				if(max<count[date]) max=count[date];
			}
		}
		if(max>=q) for(ans=1;ans<101;++ans) if(count[ans]==max&&q<=count[ans]) break;
		cout<<ans<<endl;
	}
	return 0;
}