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

public class Main {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();

		Set<Integer> foods = new HashSet<Integer>();
		for (int i = 0; i < m; i++) {
			foods.add(i+1);
		}

		Set<Integer> nextFoods = new HashSet<Integer>();
		for (int i = 0; i < n; i++) {
			int k = scanner.nextInt();
			for (int j = 0; j < k; j++) {
				int a = scanner.nextInt();
				if (foods.contains(a)) {
					nextFoods.add(a);
				}
			}
			foods = nextFoods;
			nextFoods = new HashSet<Integer>();
		}

		System.out.println(foods.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 {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();

		Set<Integer> foods = new HashSet<Integer>();
		for (int i = 0; i < m; i++) {
			foods.add(i+1);
		}

		Set<Integer> nextFoods = new HashSet<Integer>();
		for (int i = 0; i < n; i++) {
			int k = scanner.nextInt();
			for (int j = 0; j < k; j++) {
				int a = scanner.nextInt();
				if (foods.contains(a)) {
					nextFoods.add(a);
				}
			}
			foods = nextFoods;
			nextFoods = new HashSet<Integer>();
		}

		System.out.println(foods.size());

	}

} Main @SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();

		Set<Integer> foods = new HashSet<Integer>();
		for (int i = 0; i < m; i++) {
			foods.add(i+1);
		}

		Set<Integer> nextFoods = new HashSet<Integer>();
		for (int i = 0; i < n; i++) {
			int k = scanner.nextInt();
			for (int j = 0; j < k; j++) {
				int a = scanner.nextInt();
				if (foods.contains(a)) {
					nextFoods.add(a);
				}
			}
			foods = nextFoods;
			nextFoods = new HashSet<Integer>();
		}

		System.out.println(foods.size());

	} main {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();

		Set<Integer> foods = new HashSet<Integer>();
		for (int i = 0; i < m; i++) {
			foods.add(i+1);
		}

		Set<Integer> nextFoods = new HashSet<Integer>();
		for (int i = 0; i < n; i++) {
			int k = scanner.nextInt();
			for (int j = 0; j < k; j++) {
				int a = scanner.nextInt();
				if (foods.contains(a)) {
					nextFoods.add(a);
				}
			}
			foods = nextFoods;
			nextFoods = new HashSet<Integer>();
		}

		System.out.println(foods.size());

	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int m = scanner.nextInt(); m scanner.nextInt() scanner.nextInt scanner Set<Integer> foods = new HashSet<Integer>(); foods new HashSet<Integer>() for (int i = 0; i < m; i++) {
			foods.add(i+1);
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			foods.add(i+1);
		} {
			foods.add(i+1);
		} foods.add(i+1) foods.add foods i+1 i 1 Set<Integer> nextFoods = new HashSet<Integer>(); nextFoods new HashSet<Integer>() for (int i = 0; i < n; i++) {
			int k = scanner.nextInt();
			for (int j = 0; j < k; j++) {
				int a = scanner.nextInt();
				if (foods.contains(a)) {
					nextFoods.add(a);
				}
			}
			foods = nextFoods;
			nextFoods = new HashSet<Integer>();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			int k = scanner.nextInt();
			for (int j = 0; j < k; j++) {
				int a = scanner.nextInt();
				if (foods.contains(a)) {
					nextFoods.add(a);
				}
			}
			foods = nextFoods;
			nextFoods = new HashSet<Integer>();
		} {
			int k = scanner.nextInt();
			for (int j = 0; j < k; j++) {
				int a = scanner.nextInt();
				if (foods.contains(a)) {
					nextFoods.add(a);
				}
			}
			foods = nextFoods;
			nextFoods = new HashSet<Integer>();
		} int k = scanner.nextInt(); k scanner.nextInt() scanner.nextInt scanner for (int j = 0; j < k; j++) {
				int a = scanner.nextInt();
				if (foods.contains(a)) {
					nextFoods.add(a);
				}
			} int j = 0; int j = 0; j 0 j < k j k j++ j++ j {
				int a = scanner.nextInt();
				if (foods.contains(a)) {
					nextFoods.add(a);
				}
			} {
				int a = scanner.nextInt();
				if (foods.contains(a)) {
					nextFoods.add(a);
				}
			} int a = scanner.nextInt(); a scanner.nextInt() scanner.nextInt scanner if (foods.contains(a)) {
					nextFoods.add(a);
				} foods.contains(a) foods.contains foods a {
					nextFoods.add(a);
				} nextFoods.add(a) nextFoods.add nextFoods a foods = nextFoods foods nextFoods nextFoods = new HashSet<Integer>() nextFoods new HashSet<Integer>() System.out.println(foods.size()) System.out.println System.out System System.out foods.size() foods.size foods String[] args args public class Main {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();

		Set<Integer> foods = new HashSet<Integer>();
		for (int i = 0; i < m; i++) {
			foods.add(i+1);
		}

		Set<Integer> nextFoods = new HashSet<Integer>();
		for (int i = 0; i < n; i++) {
			int k = scanner.nextInt();
			for (int j = 0; j < k; j++) {
				int a = scanner.nextInt();
				if (foods.contains(a)) {
					nextFoods.add(a);
				}
			}
			foods = nextFoods;
			nextFoods = new HashSet<Integer>();
		}

		System.out.println(foods.size());

	}

} public class Main {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();

		Set<Integer> foods = new HashSet<Integer>();
		for (int i = 0; i < m; i++) {
			foods.add(i+1);
		}

		Set<Integer> nextFoods = new HashSet<Integer>();
		for (int i = 0; i < n; i++) {
			int k = scanner.nextInt();
			for (int j = 0; j < k; j++) {
				int a = scanner.nextInt();
				if (foods.contains(a)) {
					nextFoods.add(a);
				}
			}
			foods = nextFoods;
			nextFoods = new HashSet<Integer>();
		}

		System.out.println(foods.size());

	}

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

public class Main {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();

		Set<Integer> foods = new HashSet<Integer>();
		for (int i = 0; i < m; i++) {
			foods.add(i+1);
		}

		Set<Integer> nextFoods = new HashSet<Integer>();
		for (int i = 0; i < n; i++) {
			int k = scanner.nextInt();
			for (int j = 0; j < k; j++) {
				int a = scanner.nextInt();
				if (foods.contains(a)) {
					nextFoods.add(a);
				}
			}
			foods = nextFoods;
			nextFoods = new HashSet<Integer>();
		}

		System.out.println(foods.size());

	}

}
