#!/usr/bin/ruby

def solve(n, m, foods_list)
  liked = [0] * m
  foods_list.each do |foods|
    foods.each do |food|
      liked[food - 1] += 1
    end
  end
  liked.select {|liked_cnt| liked_cnt == n}.size
end

def each_case(sin)
  n, m = sin.gets.chomp.split(" ").map(&:to_i)
  foods_list = []
  while ln = sin.gets
    _, *foods = ln.chomp.split(" ").map(&:to_i)
    foods_list.push foods
  end
  yield n, m, foods_list
end

each_case(STDIN) do |n, m, foods_list|
  puts solve(n, m, foods_list).to_s
end


