Problem:
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

Solution in PHP7 (7.0.15) (judge verdict: Accepted)

<?php /*atcoder.php*/

$at = new Atcoder();
$at->main();
unset($at);

class Atcoder{
	private function arrayIn(){
		$buf = explode(" ", fgets(STDIN));
		return $this->killNewLine($buf);
	}
	private function killNewLine($buf = null){
		$buf = str_replace("\r\n", "", $buf);
		$buf = str_replace("\n", "", $buf);
		$buf = str_replace("\r", "", $buf);
		return $buf;
	}

	public function main(){
		$s = $this->arrayIn();
		
		$n = $s[0];
		$m = $s[1];

		$buf = array();
		$b = array_fill(1, 30, 0);
		$ans = 0;
		
		for($i = 0; $i < $n; $i++){
			$buf = $this->arrayIn();	
			for($j = 0; $j < $buf[0]; $j++){
				switch ($buf[$j + 1]){
					case(1):
					$b[1]++;
					break;
					case(2):
					$b[2]++;
					break;
					case(3):
					$b[3]++;
					break;
					case(4):
					$b[4]++;
					break;
					case(5):
					$b[5]++;
					break;
					case(6):
					$b[6]++;
					break;
					case(7):
					$b[7]++;
					break;
					case(8):
					$b[8]++;
					break;
					case(9):
					$b[9]++;
					break;
					case(10):
					$b[10]++;
					break;
					case(11):
					$b[11]++;
					break;
					case(12):
					$b[12]++;
					break;
					case(13):
					$b[13]++;
					break;
					case(14):
					$b[14]++;
					break;
					case(15):
					$b[15]++;
					break;
					case(16):
					$b[16]++;
					break;
					case(17):
					$b[17]++;
					break;
					case(18):
					$b[18]++;
					break;
					case(19):
					$b[19]++;
					break;
					case(20):
					$b[20]++;
					break;
					case(21):
					$b[21]++;
					break;
					case(22):
					$b[22]++;
					break;
					case(23):
					$b[23]++;
					break;
					case(24):
					$b[24]++;
					break;
					case(25):
					$b[25]++;
					break;
					case(26):
					$b[26]++;
					break;
					case(27):
					$b[27]++;
					break;
					case(28):
					$b[28]++;
					break;
					case(29):
					$b[29]++;
					break;
					case(30):
					$b[30]++;
					break;
					default:
					break;
				}
			}
		}

		for($i = 0; $i < $m; $i++){
			if($n == $b[$i + 1]){
				$ans++;
			}
		}

		echo $ans . "\n";

	}
}
?>