#include<stdio.h>

int main(void){
  int i,j;
  int n,q;
  int m,d,a[100];
  int max,ans;
  
  while(1){
    scanf("%d %d ",&n,&q);
    if(!n && !q)break;

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

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