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

#define N 100

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    int b[ N ] = { };
    int n, q;
    int res;

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

    while ( n-- )
    {
      int m;

      scanf ( "%d", &m );
      while ( m-- )
      {
        int d;

        scanf ( "%d", &d );
        ++b[ d ];
      }
    }

    res = 1;
    for ( i = 2; i < N; ++i )
    {
      if ( b[ i ] > b[ res ] )
        res = i;
    }
    printf ( "%d\n", b[ res ] >= q ? res : 0 );
  }

  return ( EXIT_SUCCESS );
}