#include <bits/stdc++.h>
using namespace std;

int n, q, now, ans, maxn, m;
int memo[1000] = {0};
string s;
// char s[1000];

int main() {
  int i, j;
  while(1) {
    cin >> n >> q;
    if(n + q == 0) break;
    ans = 0;
    maxn = 0;
    for(i = 0; i < n; ++i) {
      cin >> m;
      for(j = 0; j < m; ++j) {
        cin >> now;
        ++memo[now];
      }
    }
    for(i = 0; i < 1000; ++i) {
      if(memo[i] >= q && memo[i] > maxn) {
        maxn = memo[i];
        ans = i;
      }
      memo[i] = 0;
    }
    cout << ans << endl;
  }
  return 0;
}

