#include <stdio.h>
#pragma warning(disable : 4996)
int N, Q, M, D, R[100];
int main() {
	while (true) {
		scanf("%d%d", &N, &Q);
		if (N == 0 && Q == 0) break;
		for (int i = 0; i < 100; i++) R[i] = 0;
		for (int i = 0; i < N; i++) {
			scanf("%d", &M);
			for (int j = 0; j < M; j++) {
				scanf("%d", &D); R[--D]++;
			}
		}
		int ptr = 0;
		for (int i = 0; i < 100; i++) {
			if (R[i] >= Q) {
				if (ptr == 0) {
					ptr = i + 1;
				}
				else if (R[i] > R[ptr - 1]) {
					ptr = i + 1;
				}
			}
		}
		printf("%d\n", ptr);
	}
	return 0;
}