#include <stdio.h>

int main()
{
  int i;
  int n, q;
  int m, date;
  int candidate[100];
  int max, date_of_meeting;
  
  while (1) {
    scanf("%d %d", &n, &q);
    if (n == 0 && q == 0) break;

    for (i = 0; i < sizeof(candidate)/sizeof(int); i++) {
      candidate[i] = 0;
    }

    while (n--) {
      scanf("%d", &m);
      while(m--) {
        scanf("%d", &date);
        candidate[date]++;
      }
    }

    max = 0;
    date_of_meeting = 0;
    for (i = 1; i < sizeof(candidate)/sizeof(int); i++) {
      if (candidate[i] > max && candidate[i] >= q) {
        max = candidate[i];
        date_of_meeting = i;
      }
    }

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

