#include <stdio.h>
#define SIZE 100

int date[SIZE + 1];

/* prototype declaration */
void init();
void count(int day);
int search(int quorum);

int main(int argc, const char *argv[])
{
	int i, j, N, Q, M, day, ans;

	while(1)
	{
		/* initialization */
		init();
		ans = 0;

		scanf("%d%d", &N, &Q);	

		if(N == 0 && Q == 0)
		{
			break;
		}

		for(i = 0; i < N; i++)
		{
			scanf("%d", &M);

			for(j = 0; j < M; j++)
			{
				scanf("%d", &day);
				count(day);
			}

			if(!ans)
			{
				ans = search(Q);
			}
		}

		printf("%d\n", ans);
	}

	return 0;
}

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

void count(int day)
{
	date[day] += 1;
}

int search(int quorum)
{
	int i, min = SIZE + 1;

	for(i = 0; i < SIZE; i++)
	{
		if(date[i] >= quorum)
		{
			min = i < min ? i : min;
		}
	}

	return min == SIZE + 1 ? 0 : min;
}