#include <iostream>
using namespace std;

int main() {
	int n,q,m,d,saidai,ans;
	while(1){
		saidai = 0;
		cin >> n >> q;
		if(n == 0)break;
		int a[101] = {};
		for(int i = 0;i < n;i++){
			cin >>m;
			for(int j = 0;j < m;j++){
				cin >> d;
				a[d]++;
			}
		}
		for(int i = 1;i < 101;i++){
			if(saidai < a[i]){
			saidai = a[i];
			ans = i;
			}
		}
		if(saidai >= q)cout << ans << endl;
		else cout << 0 << endl;
	}
	return 0;
}