#include <stdio.h>

int member_num,quorum;
int list[100];

int main(void) {
	int i,j;
	int date_num,date;
	int max_date,max_num;
	while(1) {
		scanf("%d%d",&member_num,&quorum);
		if(member_num==0 && quorum==0)break;
		for(i=0;i<100;i++)list[i]=0;
		for(i=0;i<member_num;i++) {
			scanf("%d",&date_num);
			for(j=0;j<date_num;j++) {
				scanf("%d",&date);
				list[date-1]++;
			}
		}
		max_date=0;max_num=0;
		for(i=0;i<100;i++) {
			if(list[i]>max_num) {
				max_num=list[i];
				max_date=i;
			}
		}
		printf("%d\n",(max_num>=quorum)?(max_date+1):0);
	}
	return 0;
}