#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int n, q;
  while(cin >> n >> q, n+q) {
    int date[110] = {};
    for(int i = 0; i < n; i++) {
      int m; cin >> m;
      for(int j = 0; j < m; j++) {
        int x; cin >> x;
        date[x]++;
      }
    }

    int mnum = q, ans = 1000;
    for(int i = 0; i < 110; i++) {
      if((date[i] == q && i < ans) || date[i] > mnum) {
        ans = i;
        mnum = date[i];
      }
    }
    if(ans == 1000) ans = 0;
    cout << ans << endl;
  }
}