// Aizu 1124: When Can We Meet?
// 2017.9.15 bal4u@uu

#include <stdio.h>
#include <string.h>

int f[102];

int main()
{
	int n, q, m, i, d, max, ans;

	while (scanf("%d%d", &n, &q) && n) {
		memset(f, 0, sizeof(f)), max = 0;
		while (n-- > 0) {
			scanf("%d", &m);
			while (m-- > 0) { scanf("%d", &d), f[d]++; if (d > max) max = d; }
		}
		for (ans = 0, i = 1; i <= max; i++) if (f[i] >= q && f[i] > f[ans]) ans = i;
		printf("%d\n", ans);
	}
	return 0;
}