//When Can We Meet?
#include <stdio.h>
int main(void){
    int N, Q;
    int M, m[100] = {};
    int count[100] = {};
    int max = 0 ,l;
    
    for ( int i = 0;; i++){
        scanf ("%d%d", &N, &Q);
        if (N == 0) break;
        max = 0;
        for (int h = 0; h < 100; h++) count[h] = 0;
        for ( int j = 0; j < N; j++){
            scanf ("%d", &M);
            for ( int k = 0; k < M; k++){
                scanf ("%d", &m[k]);
                count[m[k]]++;
                if (max < count[m[k]]) max = count[m[k]];
            }
        }
        for ( l = 0; l < 100; l++){
            if (count[l] >= Q && count[l] == max ){
                printf ("%d\n", l);
                break;
            }
        }
        if (l == 100) printf ("0\n");
    }
}