n, m = gets.split.map(&:to_i)
ka = []
n.times do
	ka << gets.split.map(&:to_i)
end

f = Hash.new(0)
ka.each do |a|
	a[1..-1].each do |k|
		f[k] += 1
	end
end
ans = 0
f.each do |k, v|
	ans += 1 if v == n
end

puts ans
