#include <bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
int main(){
	while(1){
		int n,q;
		cin>>n>>q;
		if(n==0&&q==0) break;
		int a[200];
		lp(i,200) a[i]=0;
		lp(i,n){
			int m;
			cin>>m;
			lp(j,m){
				int b;
				cin>>b;
				a[b]++;
			}
		}
		int max=-1,memo=0;
		lp(i,101){
			if(a[i]>max){
				max=a[i];
				memo=i;
			}
		}
		if(max<q) cout<<"0"<<endl;
		else cout<<memo<<endl;
	}

	return 0;
}
