#include <cstdio>
using namespace std;

int main(){
	
	int n,q,m,da,res;
	int i;
	int date[100] = {0};
	while(true){
		
		res = 0;
		for(i=0;i<sizeof(date)/sizeof(int);i++){
			date[i] = 0;
		}
		
		scanf(" %d %d", &n, &q);
		if(n == 0 & q == 0){
			break;
		}
		
		for(i=0;i<n;i++){
			scanf(" %d", &m);
			for(int j=0;j<m;j++){
				scanf(" %d", &da);
				date[da] ++;
			}
		}
		for(i=0;i<100;i++){
			if(date[res] < date[i]){
				res = i;
			}
		}
		if(date[res] >= q){
			printf("%d\n", res);
		}else{
			printf("0\n");
		}
	}
	
	return 0;
}