n, m = gets.split.map &:to_i
c = Array.new(m, 0)
n.times do
    a = gets.split.map &:to_i
    l = a.shift
    l.times do |i|
        c[a[i]-1] += 1
    end
end
cnt = 0

m.times do |i|
    cnt += 1 if c[i] == n
end
puts cnt
