#include<iostream>
#include<vector>

using namespace std;

int main(void){

  int n,q;

  while(cin >> n >> q, n|q){
    vector<int>v(101,0);
    int m,d;
    for(int i=0;i<n;i++){
      cin >> m;
      while(m--)cin >> d, v[d]++;
    }

    int ans=0;
    for(int i=0;i<101;i++){
      if(v[i]>=q && v[i]>v[ans])ans = i; 
    }
    
    cout << ans << endl;
  }
  
  return 0;
}