function main(input) {
    const args = input.split('\n');
    const Args = args[0].split(' ')
    const N = parseInt(Args[0], 10)
    const M = parseInt(Args[1], 10)

    var ans = [];
    var temp_ans = [];
    for(var i = 1; i <= M; i++) {
        ans.push(i);
    }

    for(var i = 1; i <= N; i++) {
        anketo = args[i].split(' ').map(Number);
        anketo.shift();
        temp_ans = isLike(ans, anketo);
        ans = temp_ans.slice();
    }
    console.log(ans.length)

}

const isLike = (arrayA, arrayB) => {
    var sukisukidaisuki = []
    arrayA.concat(arrayB).forEach(element => {
        if (arrayA.indexOf(element) !== -1 && arrayB.indexOf(element) !== -1) {
            if(sukisukidaisuki.indexOf(element) === -1) {
                sukisukidaisuki.push(element);
            }
        }
    })

    return sukisukidaisuki;
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
