line = gets.chomp.split.map(&:to_i)

n = line[0]
m = line[1]

favorite_food = Array.new(m, 0)

n.times do
    line = gets.chomp.split.map(&:to_i)
    line.delete_at(0)
    line.each do |food|
        favorite_food[food - 1] += 1
    end
end

ans = 0
favorite_food.each do |num|
    ans += 1 if n == num
end

puts ans
