array = gets.split.map{|a|a.to_i}
n,m = array[0], array[1]
ki =[]
for i in(0..n-1)
  ki[i] = gets.split.map{|a|a.to_i}
  ki[i].shift
end
ans =0

for i in(1..m)
  num = 0
  for j in(0..n-1)
  if ki[j].include?(i)
    num +=1
  end
  if num== n then
    ans +=1
  end
end
end
puts ans
