#include <stdio.h>

int main(){
	int N, Q;
	int M, data;
	int canAttend[100];
	int i,j;
	int maxMember,maxMemberdata;
	while(1){
		scanf("%d%d",&N,&Q);if(N==0&&Q==0) {return-1;}
		maxMember=Q-1;
		maxMemberdata=0;
		for(j=0;j<100;j++) canAttend[j]=0;
		for(i=0;i<N;i++){
			scanf("%d", &M);
			for(j=0;j<M;j++){
				scanf("%d", &data);
				canAttend[data]=canAttend[data]+1;
			}
		}
		for(i=0;i<100;i++){
			if(canAttend[i]>maxMember){
				maxMember=canAttend[i];
				maxMemberdata=i;
			}
		}
		printf("%d\n",maxMemberdata);
	}
	return 0;
}