line = gets.split(' ')
N = line[0].to_i
M = line[1].to_i

array = Array.new(40, 0)

for i in 1..N do
    line = gets.split(' ')
    k = line[0].to_i
    puts k
    for j in 1..k do
        array[line[j].to_i] += 1
    end
end

ret = 0
for i in 1..M do
    if array[i] == N then
        ret += 1
    end
end

puts ret
