#include <stdio.h>
#define MAX_N 51
#define MAX_M 51
#define MAX_COUNT 101

int count[MAX_COUNT];

void init(void) {
  int i;
  for (i = 0; i < MAX_COUNT; i++)
    count[i] = 0;
}

int main(void) {
  int n, q, m, t, i, j, max, maxp;
  while (1) {
    init();
    scanf("%d %d", &n, &q);
    if (n == 0 && q == 0) return 0;

    for (i = 0; i < n; i++) {
      scanf("%d", &m);
      for (j = 0; j < m; j++) {
	scanf("%d", &t);
	count[t]++;
      }
    }

    max = 0;
    maxp = 0;
    for (i = 1; i < MAX_COUNT; i++) {
      if (count[i] >= q && count[i] > max) {
	max = count[i];
	maxp = i;
      }
    }
    printf("%d\n", maxp);
  }
}