import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int N, M, ans=0;
		int Food[][];
		Scanner scan = new Scanner(System.in);
		
		N = scan.nextInt();
		M = scan.nextInt();
		Food = new int[N+1][M];
		
		for(int i=0; i<M;i++) {
			Food[N][i] = 1;
		}
		
		int A, K;
		for(int i=0; i<N; i++) {
			K = scan.nextInt();
			for(int j=0; j<K; j++) {
				A = scan.nextInt();
				Food[i][A-1] = 1;
			}
		}
		for(int i=0; i<M; i++) {
			for(int j=0; j<N; j++) {
				Food[N][i] *= Food[j][i];
			}
		}
		for(int i=0; i<M; i++) {
			ans += Food[N][i];
		}
		System.out.print(ans);
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		int N, M, ans=0;
		int Food[][];
		Scanner scan = new Scanner(System.in);
		
		N = scan.nextInt();
		M = scan.nextInt();
		Food = new int[N+1][M];
		
		for(int i=0; i<M;i++) {
			Food[N][i] = 1;
		}
		
		int A, K;
		for(int i=0; i<N; i++) {
			K = scan.nextInt();
			for(int j=0; j<K; j++) {
				A = scan.nextInt();
				Food[i][A-1] = 1;
			}
		}
		for(int i=0; i<M; i++) {
			for(int j=0; j<N; j++) {
				Food[N][i] *= Food[j][i];
			}
		}
		for(int i=0; i<M; i++) {
			ans += Food[N][i];
		}
		System.out.print(ans);
	}

} Main public static void main(String[] args) {
		int N, M, ans=0;
		int Food[][];
		Scanner scan = new Scanner(System.in);
		
		N = scan.nextInt();
		M = scan.nextInt();
		Food = new int[N+1][M];
		
		for(int i=0; i<M;i++) {
			Food[N][i] = 1;
		}
		
		int A, K;
		for(int i=0; i<N; i++) {
			K = scan.nextInt();
			for(int j=0; j<K; j++) {
				A = scan.nextInt();
				Food[i][A-1] = 1;
			}
		}
		for(int i=0; i<M; i++) {
			for(int j=0; j<N; j++) {
				Food[N][i] *= Food[j][i];
			}
		}
		for(int i=0; i<M; i++) {
			ans += Food[N][i];
		}
		System.out.print(ans);
	} main {
		int N, M, ans=0;
		int Food[][];
		Scanner scan = new Scanner(System.in);
		
		N = scan.nextInt();
		M = scan.nextInt();
		Food = new int[N+1][M];
		
		for(int i=0; i<M;i++) {
			Food[N][i] = 1;
		}
		
		int A, K;
		for(int i=0; i<N; i++) {
			K = scan.nextInt();
			for(int j=0; j<K; j++) {
				A = scan.nextInt();
				Food[i][A-1] = 1;
			}
		}
		for(int i=0; i<M; i++) {
			for(int j=0; j<N; j++) {
				Food[N][i] *= Food[j][i];
			}
		}
		for(int i=0; i<M; i++) {
			ans += Food[N][i];
		}
		System.out.print(ans);
	} int N N M M ans=0; ans 0 int Food[][]; Food Scanner scan = new Scanner(System.in); scan new Scanner(System.in) N = scan.nextInt() N scan.nextInt() scan.nextInt scan M = scan.nextInt() M scan.nextInt() scan.nextInt scan Food = new int[N+1][M] Food new int[N+1][M] N+1 N 1 M for(int i=0; i<M;i++) {
			Food[N][i] = 1;
		} int i=0; int i=0; i 0 i<M i M i++ i++ i {
			Food[N][i] = 1;
		} {
			Food[N][i] = 1;
		} Food[N][i] = 1 Food[N][i] Food[N] Food N i 1 int A A K; K for(int i=0; i<N; i++) {
			K = scan.nextInt();
			for(int j=0; j<K; j++) {
				A = scan.nextInt();
				Food[i][A-1] = 1;
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			K = scan.nextInt();
			for(int j=0; j<K; j++) {
				A = scan.nextInt();
				Food[i][A-1] = 1;
			}
		} {
			K = scan.nextInt();
			for(int j=0; j<K; j++) {
				A = scan.nextInt();
				Food[i][A-1] = 1;
			}
		} K = scan.nextInt() K scan.nextInt() scan.nextInt scan for(int j=0; j<K; j++) {
				A = scan.nextInt();
				Food[i][A-1] = 1;
			} int j=0; int j=0; j 0 j<K j K j++ j++ j {
				A = scan.nextInt();
				Food[i][A-1] = 1;
			} {
				A = scan.nextInt();
				Food[i][A-1] = 1;
			} A = scan.nextInt() A scan.nextInt() scan.nextInt scan Food[i][A-1] = 1 Food[i][A-1] Food[i] Food i A-1 A 1 1 for(int i=0; i<M; i++) {
			for(int j=0; j<N; j++) {
				Food[N][i] *= Food[j][i];
			}
		} int i=0; int i=0; i 0 i<M i M i++ i++ i {
			for(int j=0; j<N; j++) {
				Food[N][i] *= Food[j][i];
			}
		} {
			for(int j=0; j<N; j++) {
				Food[N][i] *= Food[j][i];
			}
		} for(int j=0; j<N; j++) {
				Food[N][i] *= Food[j][i];
			} int j=0; int j=0; j 0 j<N j N j++ j++ j {
				Food[N][i] *= Food[j][i];
			} {
				Food[N][i] *= Food[j][i];
			} Food[N][i] *= Food[j][i] Food[N][i] Food[N] Food N i Food[j][i] Food[j] Food j i for(int i=0; i<M; i++) {
			ans += Food[N][i];
		} int i=0; int i=0; i 0 i<M i M i++ i++ i {
			ans += Food[N][i];
		} {
			ans += Food[N][i];
		} ans += Food[N][i] ans Food[N][i] Food[N] Food N i System.out.print(ans) System.out.print System.out System System.out ans String[] args args public class Main {

	public static void main(String[] args) {
		int N, M, ans=0;
		int Food[][];
		Scanner scan = new Scanner(System.in);
		
		N = scan.nextInt();
		M = scan.nextInt();
		Food = new int[N+1][M];
		
		for(int i=0; i<M;i++) {
			Food[N][i] = 1;
		}
		
		int A, K;
		for(int i=0; i<N; i++) {
			K = scan.nextInt();
			for(int j=0; j<K; j++) {
				A = scan.nextInt();
				Food[i][A-1] = 1;
			}
		}
		for(int i=0; i<M; i++) {
			for(int j=0; j<N; j++) {
				Food[N][i] *= Food[j][i];
			}
		}
		for(int i=0; i<M; i++) {
			ans += Food[N][i];
		}
		System.out.print(ans);
	}

} public class Main {

	public static void main(String[] args) {
		int N, M, ans=0;
		int Food[][];
		Scanner scan = new Scanner(System.in);
		
		N = scan.nextInt();
		M = scan.nextInt();
		Food = new int[N+1][M];
		
		for(int i=0; i<M;i++) {
			Food[N][i] = 1;
		}
		
		int A, K;
		for(int i=0; i<N; i++) {
			K = scan.nextInt();
			for(int j=0; j<K; j++) {
				A = scan.nextInt();
				Food[i][A-1] = 1;
			}
		}
		for(int i=0; i<M; i++) {
			for(int j=0; j<N; j++) {
				Food[N][i] *= Food[j][i];
			}
		}
		for(int i=0; i<M; i++) {
			ans += Food[N][i];
		}
		System.out.print(ans);
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int N, M, ans=0;
		int Food[][];
		Scanner scan = new Scanner(System.in);
		
		N = scan.nextInt();
		M = scan.nextInt();
		Food = new int[N+1][M];
		
		for(int i=0; i<M;i++) {
			Food[N][i] = 1;
		}
		
		int A, K;
		for(int i=0; i<N; i++) {
			K = scan.nextInt();
			for(int j=0; j<K; j++) {
				A = scan.nextInt();
				Food[i][A-1] = 1;
			}
		}
		for(int i=0; i<M; i++) {
			for(int j=0; j<N; j++) {
				Food[N][i] *= Food[j][i];
			}
		}
		for(int i=0; i<M; i++) {
			ans += Food[N][i];
		}
		System.out.print(ans);
	}

}
