#include <iostream>

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)

using namespace std;

int    nextInt()    { int d;      cin >> d;   return d;   }
string nextString() { string str; cin >> str; return str; }

int main() {
  while(true) {
    int N = nextInt();
    int Q = nextInt();
    if (N + Q == 0) break;
    
    int D[101] = {0};
    REP(i, N) {
      int M = nextInt();
      REP(j, M) {
        int d = nextInt();
        D[d]++;
      }
    }
    
    int max_d = -1;
    int max_idx;
    REP(i, 101) {
      if (D[i] > max_d) {
        max_d = D[i];
        max_idx = i;
      }
    }
    if (max_d < Q) {
      cout << 0 << endl;
    } else {
      cout << max_idx << endl;
    }
  }
  return 0;
}
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

int main(){
    int n, q;
    while(cin >> n >> q, n != 0 && q != 0){
        map<int,int> c;
        for(int i=0; i<n; ++i){
            int m;
            cin >> m;
            for(int j=0; j<m; ++j){
                int tmp;
                cin >> tmp;
                if(c.find(tmp) == c.end())
                    c.insert(map<int,int>::value_type(tmp,1));
                else
                    ++c[tmp];
            }
        }
        map<int,int>::iterator it = c.begin();
        int max = 0, res = 0;
        while(it!=c.end()){
            if(max < (*it).second && q <= (*it).second){
                max = (*it).second;
                res = (*it).first;
            }
            ++it;
        }
        cout << res << endl;
    }
    return 0;
}