import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
      
		List<String[]> arrList = new ArrayList<>(); 
		while(sc.hasNextLine()) {
			String s = sc.nextLine();
          	if("".equals(s)){
              continue;
            }
			arrList.add(s.split(" "));
		}
		sc.close();

		Map<Integer, Integer> ansMap = new HashMap<>();
		for(int j=1; j<=m; j++) {
			ansMap.put(Integer.valueOf(j), Integer.valueOf(0));
		}
		for(String[] strArr : arrList) {
			makeMap(ansMap, strArr);
		}
		
		int ans = 0;
		for(Map.Entry<Integer, Integer> entry : ansMap.entrySet()) {
			if (entry.getValue() == n) {
				ans++;
			}
		}
		System.out.println(ans);
	}
	
	private static void makeMap(Map<Integer, Integer> ansMap, String[] arr) {
		int size = Integer.parseInt(arr[0]);
		for(int i=1; i<=size; i++) {
			Integer key = Integer.parseInt(arr[i]);
			int a = ansMap.get(key).intValue();
			ansMap.put(key, Integer.valueOf(a+1));
		}
	}
} import java.util.ArrayList; ArrayList java.util import java.util.HashMap; HashMap java.util import java.util.List; List java.util import java.util.Map; Map java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
      
		List<String[]> arrList = new ArrayList<>(); 
		while(sc.hasNextLine()) {
			String s = sc.nextLine();
          	if("".equals(s)){
              continue;
            }
			arrList.add(s.split(" "));
		}
		sc.close();

		Map<Integer, Integer> ansMap = new HashMap<>();
		for(int j=1; j<=m; j++) {
			ansMap.put(Integer.valueOf(j), Integer.valueOf(0));
		}
		for(String[] strArr : arrList) {
			makeMap(ansMap, strArr);
		}
		
		int ans = 0;
		for(Map.Entry<Integer, Integer> entry : ansMap.entrySet()) {
			if (entry.getValue() == n) {
				ans++;
			}
		}
		System.out.println(ans);
	}
	
	private static void makeMap(Map<Integer, Integer> ansMap, String[] arr) {
		int size = Integer.parseInt(arr[0]);
		for(int i=1; i<=size; i++) {
			Integer key = Integer.parseInt(arr[i]);
			int a = ansMap.get(key).intValue();
			ansMap.put(key, Integer.valueOf(a+1));
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
      
		List<String[]> arrList = new ArrayList<>(); 
		while(sc.hasNextLine()) {
			String s = sc.nextLine();
          	if("".equals(s)){
              continue;
            }
			arrList.add(s.split(" "));
		}
		sc.close();

		Map<Integer, Integer> ansMap = new HashMap<>();
		for(int j=1; j<=m; j++) {
			ansMap.put(Integer.valueOf(j), Integer.valueOf(0));
		}
		for(String[] strArr : arrList) {
			makeMap(ansMap, strArr);
		}
		
		int ans = 0;
		for(Map.Entry<Integer, Integer> entry : ansMap.entrySet()) {
			if (entry.getValue() == n) {
				ans++;
			}
		}
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
      
		List<String[]> arrList = new ArrayList<>(); 
		while(sc.hasNextLine()) {
			String s = sc.nextLine();
          	if("".equals(s)){
              continue;
            }
			arrList.add(s.split(" "));
		}
		sc.close();

		Map<Integer, Integer> ansMap = new HashMap<>();
		for(int j=1; j<=m; j++) {
			ansMap.put(Integer.valueOf(j), Integer.valueOf(0));
		}
		for(String[] strArr : arrList) {
			makeMap(ansMap, strArr);
		}
		
		int ans = 0;
		for(Map.Entry<Integer, Integer> entry : ansMap.entrySet()) {
			if (entry.getValue() == n) {
				ans++;
			}
		}
		System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc List<String[]> arrList = new ArrayList<>(); arrList new ArrayList<>() while(sc.hasNextLine()) {
			String s = sc.nextLine();
          	if("".equals(s)){
              continue;
            }
			arrList.add(s.split(" "));
		} sc.hasNextLine() sc.hasNextLine sc {
			String s = sc.nextLine();
          	if("".equals(s)){
              continue;
            }
			arrList.add(s.split(" "));
		} String s = sc.nextLine(); s sc.nextLine() sc.nextLine sc if("".equals(s)){
              continue;
            } "".equals(s) "".equals "" s {
              continue;
            } continue; arrList.add(s.split(" ")) arrList.add arrList s.split(" ") s.split s " " sc.close() sc.close sc Map<Integer, Integer> ansMap = new HashMap<>(); ansMap new HashMap<>() for(int j=1; j<=m; j++) {
			ansMap.put(Integer.valueOf(j), Integer.valueOf(0));
		} int j=1; int j=1; j 1 j<=m j m j++ j++ j {
			ansMap.put(Integer.valueOf(j), Integer.valueOf(0));
		} {
			ansMap.put(Integer.valueOf(j), Integer.valueOf(0));
		} ansMap.put(Integer.valueOf(j), Integer.valueOf(0)) ansMap.put ansMap Integer.valueOf(j) Integer.valueOf Integer j Integer.valueOf(0) Integer.valueOf Integer 0 for(String[] strArr : arrList) {
			makeMap(ansMap, strArr);
		} String[] strArr arrList {
			makeMap(ansMap, strArr);
		} {
			makeMap(ansMap, strArr);
		} makeMap(ansMap, strArr) makeMap ansMap strArr int ans = 0; ans 0 for(Map.Entry<Integer, Integer> entry : ansMap.entrySet()) {
			if (entry.getValue() == n) {
				ans++;
			}
		} Map.Entry<Integer, Integer> entry ansMap.entrySet() ansMap.entrySet ansMap {
			if (entry.getValue() == n) {
				ans++;
			}
		} {
			if (entry.getValue() == n) {
				ans++;
			}
		} if (entry.getValue() == n) {
				ans++;
			} entry.getValue() == n entry.getValue() entry.getValue entry n {
				ans++;
			} ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args private static void makeMap(Map<Integer, Integer> ansMap, String[] arr) {
		int size = Integer.parseInt(arr[0]);
		for(int i=1; i<=size; i++) {
			Integer key = Integer.parseInt(arr[i]);
			int a = ansMap.get(key).intValue();
			ansMap.put(key, Integer.valueOf(a+1));
		}
	} makeMap {
		int size = Integer.parseInt(arr[0]);
		for(int i=1; i<=size; i++) {
			Integer key = Integer.parseInt(arr[i]);
			int a = ansMap.get(key).intValue();
			ansMap.put(key, Integer.valueOf(a+1));
		}
	} int size = Integer.parseInt(arr[0]); size Integer.parseInt(arr[0]) Integer.parseInt Integer arr[0] arr 0 for(int i=1; i<=size; i++) {
			Integer key = Integer.parseInt(arr[i]);
			int a = ansMap.get(key).intValue();
			ansMap.put(key, Integer.valueOf(a+1));
		} int i=1; int i=1; i 1 i<=size i size i++ i++ i {
			Integer key = Integer.parseInt(arr[i]);
			int a = ansMap.get(key).intValue();
			ansMap.put(key, Integer.valueOf(a+1));
		} {
			Integer key = Integer.parseInt(arr[i]);
			int a = ansMap.get(key).intValue();
			ansMap.put(key, Integer.valueOf(a+1));
		} Integer key = Integer.parseInt(arr[i]); key Integer.parseInt(arr[i]) Integer.parseInt Integer arr[i] arr i int a = ansMap.get(key).intValue(); a ansMap.get(key).intValue() ansMap.get(key).intValue ansMap.get(key) ansMap.get ansMap key ansMap.put(key, Integer.valueOf(a+1)) ansMap.put ansMap key Integer.valueOf(a+1) Integer.valueOf Integer a+1 a 1 Map<Integer, Integer> ansMap ansMap String[] arr arr public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
      
		List<String[]> arrList = new ArrayList<>(); 
		while(sc.hasNextLine()) {
			String s = sc.nextLine();
          	if("".equals(s)){
              continue;
            }
			arrList.add(s.split(" "));
		}
		sc.close();

		Map<Integer, Integer> ansMap = new HashMap<>();
		for(int j=1; j<=m; j++) {
			ansMap.put(Integer.valueOf(j), Integer.valueOf(0));
		}
		for(String[] strArr : arrList) {
			makeMap(ansMap, strArr);
		}
		
		int ans = 0;
		for(Map.Entry<Integer, Integer> entry : ansMap.entrySet()) {
			if (entry.getValue() == n) {
				ans++;
			}
		}
		System.out.println(ans);
	}
	
	private static void makeMap(Map<Integer, Integer> ansMap, String[] arr) {
		int size = Integer.parseInt(arr[0]);
		for(int i=1; i<=size; i++) {
			Integer key = Integer.parseInt(arr[i]);
			int a = ansMap.get(key).intValue();
			ansMap.put(key, Integer.valueOf(a+1));
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
      
		List<String[]> arrList = new ArrayList<>(); 
		while(sc.hasNextLine()) {
			String s = sc.nextLine();
          	if("".equals(s)){
              continue;
            }
			arrList.add(s.split(" "));
		}
		sc.close();

		Map<Integer, Integer> ansMap = new HashMap<>();
		for(int j=1; j<=m; j++) {
			ansMap.put(Integer.valueOf(j), Integer.valueOf(0));
		}
		for(String[] strArr : arrList) {
			makeMap(ansMap, strArr);
		}
		
		int ans = 0;
		for(Map.Entry<Integer, Integer> entry : ansMap.entrySet()) {
			if (entry.getValue() == n) {
				ans++;
			}
		}
		System.out.println(ans);
	}
	
	private static void makeMap(Map<Integer, Integer> ansMap, String[] arr) {
		int size = Integer.parseInt(arr[0]);
		for(int i=1; i<=size; i++) {
			Integer key = Integer.parseInt(arr[i]);
			int a = ansMap.get(key).intValue();
			ansMap.put(key, Integer.valueOf(a+1));
		}
	}
} Main
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
      
		List<String[]> arrList = new ArrayList<>(); 
		while(sc.hasNextLine()) {
			String s = sc.nextLine();
          	if("".equals(s)){
              continue;
            }
			arrList.add(s.split(" "));
		}
		sc.close();

		Map<Integer, Integer> ansMap = new HashMap<>();
		for(int j=1; j<=m; j++) {
			ansMap.put(Integer.valueOf(j), Integer.valueOf(0));
		}
		for(String[] strArr : arrList) {
			makeMap(ansMap, strArr);
		}
		
		int ans = 0;
		for(Map.Entry<Integer, Integer> entry : ansMap.entrySet()) {
			if (entry.getValue() == n) {
				ans++;
			}
		}
		System.out.println(ans);
	}
	
	private static void makeMap(Map<Integer, Integer> ansMap, String[] arr) {
		int size = Integer.parseInt(arr[0]);
		for(int i=1; i<=size; i++) {
			Integer key = Integer.parseInt(arr[i]);
			int a = ansMap.get(key).intValue();
			ansMap.put(key, Integer.valueOf(a+1));
		}
	}
}
