require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n,m = gets.chomp.split.map(&:to_i)
k = []
n.times do
  k.push gets.chomp.split.map(&:to_i).slice(1, m)
end

ans = 0
1.upto(m).each do |i|
  if k.all?{|man| man.include?(i)}
    ans += 1
  end
end

puts ans
