import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
class Main {
	public static void main(String[]args) {
		Scanner scan = new Scanner(System.in);
		int n =scan.nextInt();
		int m = scan.nextInt();
		int arr[] = new int[n];
		Set<Integer> s = new HashSet<>();
		for(int i = 0 ; i < n ; i++) {

			ArrayList<Integer> a = new ArrayList<>();
			int u = scan.nextInt();
			for(int j = 0 ; j <u ; j++){
			     if(i == 0) {
			    	 s.add(scan.nextInt()) ;
			     }else {
			    	 a.add(scan.nextInt()) ;
			     }
			}
			if(i!=0)
				s.retainAll(a);
		}
		
		System.out.println(s.size());
		

	}
} import java.util.ArrayList; ArrayList java.util import java.util.HashSet; HashSet java.util import java.util.Scanner; Scanner java.util import java.util.Set; Set java.util class Main {
	public static void main(String[]args) {
		Scanner scan = new Scanner(System.in);
		int n =scan.nextInt();
		int m = scan.nextInt();
		int arr[] = new int[n];
		Set<Integer> s = new HashSet<>();
		for(int i = 0 ; i < n ; i++) {

			ArrayList<Integer> a = new ArrayList<>();
			int u = scan.nextInt();
			for(int j = 0 ; j <u ; j++){
			     if(i == 0) {
			    	 s.add(scan.nextInt()) ;
			     }else {
			    	 a.add(scan.nextInt()) ;
			     }
			}
			if(i!=0)
				s.retainAll(a);
		}
		
		System.out.println(s.size());
		

	}
} Main public static void main(String[]args) {
		Scanner scan = new Scanner(System.in);
		int n =scan.nextInt();
		int m = scan.nextInt();
		int arr[] = new int[n];
		Set<Integer> s = new HashSet<>();
		for(int i = 0 ; i < n ; i++) {

			ArrayList<Integer> a = new ArrayList<>();
			int u = scan.nextInt();
			for(int j = 0 ; j <u ; j++){
			     if(i == 0) {
			    	 s.add(scan.nextInt()) ;
			     }else {
			    	 a.add(scan.nextInt()) ;
			     }
			}
			if(i!=0)
				s.retainAll(a);
		}
		
		System.out.println(s.size());
		

	} main {
		Scanner scan = new Scanner(System.in);
		int n =scan.nextInt();
		int m = scan.nextInt();
		int arr[] = new int[n];
		Set<Integer> s = new HashSet<>();
		for(int i = 0 ; i < n ; i++) {

			ArrayList<Integer> a = new ArrayList<>();
			int u = scan.nextInt();
			for(int j = 0 ; j <u ; j++){
			     if(i == 0) {
			    	 s.add(scan.nextInt()) ;
			     }else {
			    	 a.add(scan.nextInt()) ;
			     }
			}
			if(i!=0)
				s.retainAll(a);
		}
		
		System.out.println(s.size());
		

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n =scan.nextInt(); n scan.nextInt() scan.nextInt scan int m = scan.nextInt(); m scan.nextInt() scan.nextInt scan int arr[] = new int[n]; arr new int[n] n Set<Integer> s = new HashSet<>(); s new HashSet<>() for(int i = 0 ; i < n ; i++) {

			ArrayList<Integer> a = new ArrayList<>();
			int u = scan.nextInt();
			for(int j = 0 ; j <u ; j++){
			     if(i == 0) {
			    	 s.add(scan.nextInt()) ;
			     }else {
			    	 a.add(scan.nextInt()) ;
			     }
			}
			if(i!=0)
				s.retainAll(a);
		} int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {

			ArrayList<Integer> a = new ArrayList<>();
			int u = scan.nextInt();
			for(int j = 0 ; j <u ; j++){
			     if(i == 0) {
			    	 s.add(scan.nextInt()) ;
			     }else {
			    	 a.add(scan.nextInt()) ;
			     }
			}
			if(i!=0)
				s.retainAll(a);
		} {

			ArrayList<Integer> a = new ArrayList<>();
			int u = scan.nextInt();
			for(int j = 0 ; j <u ; j++){
			     if(i == 0) {
			    	 s.add(scan.nextInt()) ;
			     }else {
			    	 a.add(scan.nextInt()) ;
			     }
			}
			if(i!=0)
				s.retainAll(a);
		} ArrayList<Integer> a = new ArrayList<>(); a new ArrayList<>() int u = scan.nextInt(); u scan.nextInt() scan.nextInt scan for(int j = 0 ; j <u ; j++){
			     if(i == 0) {
			    	 s.add(scan.nextInt()) ;
			     }else {
			    	 a.add(scan.nextInt()) ;
			     }
			} int j = 0 ; int j = 0 ; j 0 j <u j u j++ j++ j {
			     if(i == 0) {
			    	 s.add(scan.nextInt()) ;
			     }else {
			    	 a.add(scan.nextInt()) ;
			     }
			} {
			     if(i == 0) {
			    	 s.add(scan.nextInt()) ;
			     }else {
			    	 a.add(scan.nextInt()) ;
			     }
			} if(i == 0) {
			    	 s.add(scan.nextInt()) ;
			     }else {
			    	 a.add(scan.nextInt()) ;
			     } i == 0 i 0 {
			    	 s.add(scan.nextInt()) ;
			     } s.add(scan.nextInt()) s.add s scan.nextInt() scan.nextInt scan {
			    	 a.add(scan.nextInt()) ;
			     } a.add(scan.nextInt()) a.add a scan.nextInt() scan.nextInt scan if(i!=0)
				s.retainAll(a); i!=0 i 0 s.retainAll(a) s.retainAll s a System.out.println(s.size()) System.out.println System.out System System.out s.size() s.size s String[]args args
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
class Main {
	public static void main(String[]args) {
		Scanner scan = new Scanner(System.in);
		int n =scan.nextInt();
		int m = scan.nextInt();
		int arr[] = new int[n];
		Set<Integer> s = new HashSet<>();
		for(int i = 0 ; i < n ; i++) {

			ArrayList<Integer> a = new ArrayList<>();
			int u = scan.nextInt();
			for(int j = 0 ; j <u ; j++){
			     if(i == 0) {
			    	 s.add(scan.nextInt()) ;
			     }else {
			    	 a.add(scan.nextInt()) ;
			     }
			}
			if(i!=0)
				s.retainAll(a);
		}
		
		System.out.println(s.size());
		

	}
}