#include<stdio.h>

int main(){
	int i,j;
	int n,m,q,d;
	int day[100];
	int max;

	while(scanf("%d%d",&n,&q),n+q){
		for(i = 0;i < 100;i++)day[i] = 0;
		for(i = 0;i < n;i++){
			scanf("%d",&m);
			for(j = 0;j < m;j++){
				scanf("%d",&d);
				day[d]++;
			}
		}
		
		max = 0;
		for(i = 0;i < 100;i++){
			if(day[max] < day[i])max = i;
		}
		if(day[max]<q)max = 0;

		printf("%d\n",max);
	}
	return 0;
}