#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define DATE_NUM 100

void readDate(int date[]) {
  int i, m, di;
  scanf("%d", &m);
  for (i=0; i<m; i++) {
    scanf("%d", &di);
    date[di]++;
  }
}

int getConvDate(int date[], int q){
  int i;
  int buf = 0, cdi = 0;
  for (i=DATE_NUM-1; i>=0; i--)
    if (date[i] >= buf && date[i] >= q) {
      buf = date[i];
      cdi = i;
    }
  return cdi;
}

void solve() {
  int n, q, m, cdi;
  int date[DATE_NUM];
  int i;

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

    for (i=0; i<DATE_NUM; i++)
      date[i] = 0;
    while (--n >= 0) {
      readDate(date);
    }
    cdi = getConvDate(date, q);
    printf("%d\n", cdi);
  }
}

int main(){
  solve();
  return 0;
}