import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		String line = null;
		try (Scanner sc = new Scanner(System.in)) {
			line = sc.nextLine();
			String[] tmpArray = line.split(" ");
			int numA = Integer.parseInt(tmpArray[0]);
			int numB = Integer.parseInt(tmpArray[1]);

			
			int[] tmpList = new int[numB];
			int tmpInd = 0;
			for (int i = 0; i < numA; i++) {
				line = sc.nextLine();
				String[] tmp = line.split(" ");
				for (int j = 0; j < tmp.length; j++) {
					if (j==0) continue;
					tmpInd = Integer.parseInt(tmp[j]);
					tmpList[tmpInd-1] ++;
				}
				}
			int reult = 0;
			for(int k : tmpList){
				if(k == numA){
					reult ++;
				}
			}
				
			System.out.println(reult);
		
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz