main(){
	int n,q;
	for(;scanf("%d%d",&n,&q)*n;){
		int c[101]={0},m,d,b=0;
		for(;n--;){
			scanf("%d",&m);
			for(;m--;){
				scanf("%d",&d);
				if(++c[d]>c[b])
					b=d;
			}
		}
		printf("%d\n",c[b]<q?0:b);
	}
}