#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;

int main() {
	while (1) {
		int N, P; cin >> N >> P;
		if (!N)break;
		vector<int>aa(100);
		for (int i = 0; i < N; ++i) {
			int a; cin >> a;
			while (a--) {
				int c; cin >> c;
				aa[c]++;
			}
		}
		int amax = 0;
		int ans = 0;
		for (int i = 99; i >=0; --i) {
			if (amax <= aa[i]) {
				amax = aa[i];
				ans = i;
			}
		}
		if (amax <P)ans = 0;
		cout << ans << endl;
	}
	return 0;
}