N,M = gets.split.map(&:to_i)
A = []
for i in 0..N-1
    A[i] = []
    A[i] = gets.strip.split.map(&:to_i)
end
B = []

for i in 0..N-1
    B[i] = A[i][0]
    A[i].delete_at(0)
end
count = 0

for i in 0..M-1

    a = 0

    for j in 0..N-1

        if A[j].none?{|x| x == i+1}

            a = 1

        end

    end

    if a == 0

        count += 1

    end

end

puts count 
       
