
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Set<Integer> favorite = new HashSet<>();
		for(int i = 1; i < M + 1; i++) {
			favorite.add(i);
		}
		for(int i = 0; i < N; i++) {
			int K = sc.nextInt();
			Set<Integer> tmp = new HashSet<>();
			for(int j = 0; j < K; j++) {
				tmp.add(sc.nextInt());
			}
			favorite.retainAll(tmp);
		}
		System.out.println(favorite.size());
	}

} import java.util.HashSet; HashSet java.util import java.util.Scanner; Scanner java.util import java.util.Set; Set 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();
		Set<Integer> favorite = new HashSet<>();
		for(int i = 1; i < M + 1; i++) {
			favorite.add(i);
		}
		for(int i = 0; i < N; i++) {
			int K = sc.nextInt();
			Set<Integer> tmp = new HashSet<>();
			for(int j = 0; j < K; j++) {
				tmp.add(sc.nextInt());
			}
			favorite.retainAll(tmp);
		}
		System.out.println(favorite.size());
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Set<Integer> favorite = new HashSet<>();
		for(int i = 1; i < M + 1; i++) {
			favorite.add(i);
		}
		for(int i = 0; i < N; i++) {
			int K = sc.nextInt();
			Set<Integer> tmp = new HashSet<>();
			for(int j = 0; j < K; j++) {
				tmp.add(sc.nextInt());
			}
			favorite.retainAll(tmp);
		}
		System.out.println(favorite.size());
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Set<Integer> favorite = new HashSet<>();
		for(int i = 1; i < M + 1; i++) {
			favorite.add(i);
		}
		for(int i = 0; i < N; i++) {
			int K = sc.nextInt();
			Set<Integer> tmp = new HashSet<>();
			for(int j = 0; j < K; j++) {
				tmp.add(sc.nextInt());
			}
			favorite.retainAll(tmp);
		}
		System.out.println(favorite.size());
	} 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 Set<Integer> favorite = new HashSet<>(); favorite new HashSet<>() for(int i = 1; i < M + 1; i++) {
			favorite.add(i);
		} int i = 1; int i = 1; i 1 i < M + 1 i M + 1 M 1 i++ i++ i {
			favorite.add(i);
		} {
			favorite.add(i);
		} favorite.add(i) favorite.add favorite i for(int i = 0; i < N; i++) {
			int K = sc.nextInt();
			Set<Integer> tmp = new HashSet<>();
			for(int j = 0; j < K; j++) {
				tmp.add(sc.nextInt());
			}
			favorite.retainAll(tmp);
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			int K = sc.nextInt();
			Set<Integer> tmp = new HashSet<>();
			for(int j = 0; j < K; j++) {
				tmp.add(sc.nextInt());
			}
			favorite.retainAll(tmp);
		} {
			int K = sc.nextInt();
			Set<Integer> tmp = new HashSet<>();
			for(int j = 0; j < K; j++) {
				tmp.add(sc.nextInt());
			}
			favorite.retainAll(tmp);
		} int K = sc.nextInt(); K sc.nextInt() sc.nextInt sc Set<Integer> tmp = new HashSet<>(); tmp new HashSet<>() for(int j = 0; j < K; j++) {
				tmp.add(sc.nextInt());
			} int j = 0; int j = 0; j 0 j < K j K j++ j++ j {
				tmp.add(sc.nextInt());
			} {
				tmp.add(sc.nextInt());
			} tmp.add(sc.nextInt()) tmp.add tmp sc.nextInt() sc.nextInt sc favorite.retainAll(tmp) favorite.retainAll favorite tmp System.out.println(favorite.size()) System.out.println System.out System System.out favorite.size() favorite.size favorite String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Set<Integer> favorite = new HashSet<>();
		for(int i = 1; i < M + 1; i++) {
			favorite.add(i);
		}
		for(int i = 0; i < N; i++) {
			int K = sc.nextInt();
			Set<Integer> tmp = new HashSet<>();
			for(int j = 0; j < K; j++) {
				tmp.add(sc.nextInt());
			}
			favorite.retainAll(tmp);
		}
		System.out.println(favorite.size());
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Set<Integer> favorite = new HashSet<>();
		for(int i = 1; i < M + 1; i++) {
			favorite.add(i);
		}
		for(int i = 0; i < N; i++) {
			int K = sc.nextInt();
			Set<Integer> tmp = new HashSet<>();
			for(int j = 0; j < K; j++) {
				tmp.add(sc.nextInt());
			}
			favorite.retainAll(tmp);
		}
		System.out.println(favorite.size());
	}

} Main

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Set<Integer> favorite = new HashSet<>();
		for(int i = 1; i < M + 1; i++) {
			favorite.add(i);
		}
		for(int i = 0; i < N; i++) {
			int K = sc.nextInt();
			Set<Integer> tmp = new HashSet<>();
			for(int j = 0; j < K; j++) {
				tmp.add(sc.nextInt());
			}
			favorite.retainAll(tmp);
		}
		System.out.println(favorite.size());
	}

}
