#include<stdio.h>
#include<stdlib.h>
#include<string.h>

/*When can we meet?
 ?????????????????????????????°?????\???????????????
 N?????°?????°???Q???????¶???°???????????????Q??\???????????????????????????????????????????????\???????????´??????????????????
 M,date1,date2,..???????????°??????????????§????????\???????????¨??¨??§N??????date???M??\?????????????????????
*/

int main() {

	int n,q;
	int m,date;
	int member[101];
	int i,j,max,max_member=0,max_date=0;

	for(;;) {
		scanf("%d %d",&n,&q);
		if(!n&&!q) break;

		for(i=0;i<n;i++) {
			scanf("%d",&m);
			for(j=0;j<m;j++) {
				scanf("%d",&date);
				member[date-1]++;
				if(max_date<date-1)
					max_date=date-1;
			}
		}
		for(i=0;i<max_date;i++)
			if(max_member<member[i]) {
				max_member=member[i];
				max=i;
			}

		if(q<=max_member)
			printf("%d\n",max);
		else
			printf("%0\n");
	}

	return 0;
}