B - Foods Loved by Everyone Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

カツサンドくんはオムライスが好きです。

他にも明太子や寿司、クリームブリュレやテンダーロインステーキなどが好きで、これらの食べ物は全て、誰もが好きだと信じています。

その仮説を証明するために、N 人の人に M 種類の食べ物について好きか嫌いかの調査を行いました。

調査の結果、i 番目の人は A_{i1} 番目, A_{i2} 番目, ..., A_{iK_i} 番目の食べ物だけ好きだと答えました。

N 人全ての人が好きだと答えた食べ物の種類数を求めてください。

制約

  • 入力は全て整数である。
  • 1 \leq N, M \leq 30
  • 1 \leq K_i \leq M
  • 1 \leq A_{ij} \leq M
  • i (1 \leq i \leq N) について A_{i1}, A_{i2}, ..., A_{iK_i} は全て異なる。

入力

入力は以下の形式で標準入力から与えられる。

N M
K_1 A_{11} A_{12} ... A_{1K_1}
K_2 A_{21} A_{22} ... A_{2K_2}
:
K_N A_{N1} A_{N2} ... A_{NK_N}

出力

N 人全ての人が好きだと答えた食べ物の種類数を出力せよ。


入力例 1

3 4
2 1 3
3 1 2 3
2 3 2

出力例 1

1

3 人全員が好きだと答えた食べ物は 3 番目の食べ物だけなので 1 を出力します。


入力例 2

5 5
4 2 3 4 5
4 1 3 4 5
4 1 2 4 5
4 1 2 3 5
4 1 2 3 4

出力例 2

0

カツサンドくんの仮説は全く正しくありませんでした。


入力例 3

1 30
3 5 10 30

出力例 3

3

Score : 200 points

Problem Statement

Katsusando loves omelette rice.

Besides, he loves crème brûlée, tenderloin steak and so on, and believes that these foods are all loved by everyone.

To prove that hypothesis, he conducted a survey on M kinds of foods and asked N people whether they like these foods or not.

The i-th person answered that he/she only likes the A_{i1}-th, A_{i2}-th, ..., A_{iK_i}-th food.

Find the number of the foods liked by all the N people.

Constraints

  • All values in input are integers.
  • 1 \leq N, M \leq 30
  • 1 \leq K_i \leq M
  • 1 \leq A_{ij} \leq M
  • For each i (1 \leq i \leq N), A_{i1}, A_{i2}, ..., A_{iK_i} are distinct.

Constraints

Input is given from Standard Input in the following format:

N M
K_1 A_{11} A_{12} ... A_{1K_1}
K_2 A_{21} A_{22} ... A_{2K_2}
:
K_N A_{N1} A_{N2} ... A_{NK_N}

Output

Print the number of the foods liked by all the N people.


Sample Input 1

3 4
2 1 3
3 1 2 3
2 3 2

Sample Output 1

1

As only the third food is liked by all the three people, 1 should be printed.


Sample Input 2

5 5
4 2 3 4 5
4 1 3 4 5
4 1 2 4 5
4 1 2 3 5
4 1 2 3 4

Sample Output 2

0

Katsusando's hypothesis turned out to be wrong.


Sample Input 3

1 30
3 5 10 30

Sample Output 3

3