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

/// 数列の読み込み
auto readNums(T = int)() {
	return readln().chomp.split.map!(to!T).array;
}

void main() {
	const nums = readNums();
	immutable n = nums[0];
	immutable m = nums[1];
	size_t[int] result;
	foreach(i; 0 .. n) {
		const knums = readNums();
		immutable k = knums[1];
		foreach(fav; knums[1 .. $]) {
			++result[fav];
		}
	}
	writefln("%s", result.byValue.count(n));
}