#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int a[101];
int main() {
	int n, q;
	while (scanf("%d%d", &n, &q), n) {
		memset(a, 0, sizeof(a));
		rep(i, n) {
			int m; scanf("%d", &m);
			rep(j, m) {
				int d; scanf("%d", &d);
				a[d]++;
			}
		}
		int Max = 0, idx;
		rep(i, 101) {
			if (Max < a[i]) {
				Max = a[i];
				idx = i;
			}
		}
		if (Max < q)puts("0");
		else printf("%d\n", idx);
	}
}