import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    const tmp = readln.split.to!(int[]);
    const N = tmp[0], M = tmp[1];
    auto res = new int[M];
    foreach (i; 0..N) {
        auto input = readln.split.to!(int[]);
        input[1..$].each!(a => res[a-1]++);
    }
    res.count!(r => r == N).writeln;
}

