import std.stdio;
import std.array;
import std.conv;
import std.algorithm;

void main()
{
  while ( true ) {
	string[] line = split( readln() );
	int n = to!int( line[ 0 ] );
	int q = to!int( line[ 1 ] );
	if ( n == 0 && q == 0 ) break;
	int[ 101 ] date;
	foreach ( i; 0 .. n ) {
	  line = split( readln() );
	  int m = to!int( line[ 0 ] );
	  foreach ( j; 0 .. m ) {
		date[ to!int( line[ j + 1 ] ) ]++;
	  }
	}
	int mx = reduce!(max)( 0, date );
	if ( mx >= q ) {
	  foreach ( i; 0 .. 100 ) {
		if ( date[ i ] == mx ) {
		  writeln( i );
		  break;
		}
	  }
	} else {
	  writeln( 0 );
	}
  }
}