n,m = gets.split.map(&:to_i)
food = Array.new(m,0)
for i in 0..n-1
  inst = gets.split.map(&:to_i)
  for j in 1..inst[0]
    food[inst[j]-1] += 1
  end
end
ans = 0
m.times {|i| ans += 1 if food[i] == n}
 puts ans
