"use strict";
function Main(input) {
    let lines = input.split("\n");
    let lines1 = lines.shift().split(/\s/).map((v) => v - 0);
    let N = lines1[0];
    let M = lines1[1];
    let Ks = new Array(M+1).fill(0);
    for (let n = 0; n < N; n++) {
        let ln = lines.shift().split(/\s/).map((v) => v - 0);
        let K = ln.shift();
        for (let m = 0; m < K; m++) {
            Ks[ln[m]] += 1;
        }
    }

    let ans = Ks.reduce((ac, value, index, array) => (value == N) ? ac + 1 : ac, 0);

    console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
