n, m = gets.chomp.split().map(&:to_i)

ans = Array.new(m, 0)
input = gets.chomp.split().map(&:to_i)
for i in 1...input.size
  ans[input[i]-1] = 1
end

(n-1).times {
  input = gets.chomp.split().map(&:to_i)
  next if input[0] == m
  
  tmp = Array.new(m, 0)
  for i in 1...input.size
    tmp[input[i]-1] = 1
  end
  
  while index = tmp.index(0)
    tmp[index] = 1
    ans[index] = 0 if ans[index] == 1
  end
}

puts ans.count(1)