#include <cstring>
#include <iostream>
using namespace std;
int main () {
	int n, q;
	while (cin >> n >> q, n || q) {
		int counts[101];
		memset(counts, 0, sizeof(counts));
		for (int i = 0; i < n; i++) {
			int m;
			cin >> m;
			for (int j = 0; j < m; j++) {
				int d;
				cin >> d;
				counts[d]++;
			}
		}
		int mcount = 0, mindex = -1;
		for (int i = 0; i <= 100; i++) {
			if (mcount < counts[i]) {
				mcount = counts[i];
				mindex = i;
			}
		}
		if (q <= mcount) {
			cout << mindex << endl;
		}
		else {
			cout << 0 << endl;
		}
	}
	return 0;
}