import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    while (true) {
        int n,q;
        scan(n,q);

        if (!n && !q) return;

        auto a = iota(n).map!(i => readln.split.to!(int[])).array;
        solve(n, q, a);
    }
}

void solve(int n, int q, int[][] a) {
    auto b = new int[](200);
    foreach (ai ; a) {
        foreach (d ; ai[1 .. $]) {
            b[d]++;
        }
    }

    int mx = b.reduce!max;

    if (mx >= q) {
        writeln(b.countUntil(mx));
    }
    else {
        writeln(0);
    }
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}