#include <stdio.h>

int main(void){

  int n,q;
  int m,d;
  int i,j;

  for(;;){

    scanf("%d %d",&n,&q);
    if(n==0&&q==0)break;

    int date[100]={0};

    for(i=0;i<n;i++){

      scanf("%d",&m);
        for(j=0;j<m;j++){
          scanf("%d",&d);
          date[d-1]++;
        }
    }

    int day = 0;
    int t = q-1;

    for(i=0;i<100;i++){
      if(date[i]>t){
        t = date[i];
        day = i + 1;
      }
    }

    printf("%d\n",day);

  }
    
  return 0;

}