n,m=gets.split.map(&:to_i)
array=[]
n.times do
	array.push(gets.split.map(&:to_i))
end
cnt=0
for i in 0..n-1
	array[i].shift
end
array.flatten!
for i in 1..m
	cnt += 1 if array.count(i)==n
end

puts cnt