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

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		final int n = sc.nextInt();
		final int m = sc.nextInt();

		HashMap<Integer, ArrayList<Integer>> list = new HashMap<Integer, ArrayList<Integer>>();
		for (int i = 1; i <= n; i++) {
			int totalItem = sc.nextInt();
			ArrayList<Integer> itemList = new ArrayList<Integer>();
			for (int j = 0; j < totalItem; j++) {
				itemList.add(sc.nextInt());
			}
			list.put(i, itemList);
		}

		int count = 0;
		int total = 0;
		for (int k = 0; k <= m; k++) {
			for (final int key : list.keySet()) {
				final ArrayList<Integer> likeItem = list.get(key);
				if (likeItem.contains(k)) {
					count++;
				}
			}
			if (count == n) {
				total++;
			}
			count = 0;
		}

		java.lang.System.out.println(total);

	}

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

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		final int n = sc.nextInt();
		final int m = sc.nextInt();

		HashMap<Integer, ArrayList<Integer>> list = new HashMap<Integer, ArrayList<Integer>>();
		for (int i = 1; i <= n; i++) {
			int totalItem = sc.nextInt();
			ArrayList<Integer> itemList = new ArrayList<Integer>();
			for (int j = 0; j < totalItem; j++) {
				itemList.add(sc.nextInt());
			}
			list.put(i, itemList);
		}

		int count = 0;
		int total = 0;
		for (int k = 0; k <= m; k++) {
			for (final int key : list.keySet()) {
				final ArrayList<Integer> likeItem = list.get(key);
				if (likeItem.contains(k)) {
					count++;
				}
			}
			if (count == n) {
				total++;
			}
			count = 0;
		}

		java.lang.System.out.println(total);

	}

} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		final int n = sc.nextInt();
		final int m = sc.nextInt();

		HashMap<Integer, ArrayList<Integer>> list = new HashMap<Integer, ArrayList<Integer>>();
		for (int i = 1; i <= n; i++) {
			int totalItem = sc.nextInt();
			ArrayList<Integer> itemList = new ArrayList<Integer>();
			for (int j = 0; j < totalItem; j++) {
				itemList.add(sc.nextInt());
			}
			list.put(i, itemList);
		}

		int count = 0;
		int total = 0;
		for (int k = 0; k <= m; k++) {
			for (final int key : list.keySet()) {
				final ArrayList<Integer> likeItem = list.get(key);
				if (likeItem.contains(k)) {
					count++;
				}
			}
			if (count == n) {
				total++;
			}
			count = 0;
		}

		java.lang.System.out.println(total);

	} main {

		Scanner sc = new Scanner(System.in);

		final int n = sc.nextInt();
		final int m = sc.nextInt();

		HashMap<Integer, ArrayList<Integer>> list = new HashMap<Integer, ArrayList<Integer>>();
		for (int i = 1; i <= n; i++) {
			int totalItem = sc.nextInt();
			ArrayList<Integer> itemList = new ArrayList<Integer>();
			for (int j = 0; j < totalItem; j++) {
				itemList.add(sc.nextInt());
			}
			list.put(i, itemList);
		}

		int count = 0;
		int total = 0;
		for (int k = 0; k <= m; k++) {
			for (final int key : list.keySet()) {
				final ArrayList<Integer> likeItem = list.get(key);
				if (likeItem.contains(k)) {
					count++;
				}
			}
			if (count == n) {
				total++;
			}
			count = 0;
		}

		java.lang.System.out.println(total);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc final int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc HashMap<Integer, ArrayList<Integer>> list = new HashMap<Integer, ArrayList<Integer>>(); list new HashMap<Integer, ArrayList<Integer>>() for (int i = 1; i <= n; i++) {
			int totalItem = sc.nextInt();
			ArrayList<Integer> itemList = new ArrayList<Integer>();
			for (int j = 0; j < totalItem; j++) {
				itemList.add(sc.nextInt());
			}
			list.put(i, itemList);
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			int totalItem = sc.nextInt();
			ArrayList<Integer> itemList = new ArrayList<Integer>();
			for (int j = 0; j < totalItem; j++) {
				itemList.add(sc.nextInt());
			}
			list.put(i, itemList);
		} {
			int totalItem = sc.nextInt();
			ArrayList<Integer> itemList = new ArrayList<Integer>();
			for (int j = 0; j < totalItem; j++) {
				itemList.add(sc.nextInt());
			}
			list.put(i, itemList);
		} int totalItem = sc.nextInt(); totalItem sc.nextInt() sc.nextInt sc ArrayList<Integer> itemList = new ArrayList<Integer>(); itemList new ArrayList<Integer>() for (int j = 0; j < totalItem; j++) {
				itemList.add(sc.nextInt());
			} int j = 0; int j = 0; j 0 j < totalItem j totalItem j++ j++ j {
				itemList.add(sc.nextInt());
			} {
				itemList.add(sc.nextInt());
			} itemList.add(sc.nextInt()) itemList.add itemList sc.nextInt() sc.nextInt sc list.put(i, itemList) list.put list i itemList int count = 0; count 0 int total = 0; total 0 for (int k = 0; k <= m; k++) {
			for (final int key : list.keySet()) {
				final ArrayList<Integer> likeItem = list.get(key);
				if (likeItem.contains(k)) {
					count++;
				}
			}
			if (count == n) {
				total++;
			}
			count = 0;
		} int k = 0; int k = 0; k 0 k <= m k m k++ k++ k {
			for (final int key : list.keySet()) {
				final ArrayList<Integer> likeItem = list.get(key);
				if (likeItem.contains(k)) {
					count++;
				}
			}
			if (count == n) {
				total++;
			}
			count = 0;
		} {
			for (final int key : list.keySet()) {
				final ArrayList<Integer> likeItem = list.get(key);
				if (likeItem.contains(k)) {
					count++;
				}
			}
			if (count == n) {
				total++;
			}
			count = 0;
		} for (final int key : list.keySet()) {
				final ArrayList<Integer> likeItem = list.get(key);
				if (likeItem.contains(k)) {
					count++;
				}
			} final int key list.keySet() list.keySet list {
				final ArrayList<Integer> likeItem = list.get(key);
				if (likeItem.contains(k)) {
					count++;
				}
			} {
				final ArrayList<Integer> likeItem = list.get(key);
				if (likeItem.contains(k)) {
					count++;
				}
			} final ArrayList<Integer> likeItem = list.get(key); likeItem list.get(key) list.get list key if (likeItem.contains(k)) {
					count++;
				} likeItem.contains(k) likeItem.contains likeItem k {
					count++;
				} count++ count if (count == n) {
				total++;
			} count == n count n {
				total++;
			} total++ total count = 0 count 0 java.lang.System.out.println(total) java.lang.System.out.println java.lang.System.out java.lang.System java.lang java java.lang java.lang.System java.lang.System.out total String[] args args public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		final int n = sc.nextInt();
		final int m = sc.nextInt();

		HashMap<Integer, ArrayList<Integer>> list = new HashMap<Integer, ArrayList<Integer>>();
		for (int i = 1; i <= n; i++) {
			int totalItem = sc.nextInt();
			ArrayList<Integer> itemList = new ArrayList<Integer>();
			for (int j = 0; j < totalItem; j++) {
				itemList.add(sc.nextInt());
			}
			list.put(i, itemList);
		}

		int count = 0;
		int total = 0;
		for (int k = 0; k <= m; k++) {
			for (final int key : list.keySet()) {
				final ArrayList<Integer> likeItem = list.get(key);
				if (likeItem.contains(k)) {
					count++;
				}
			}
			if (count == n) {
				total++;
			}
			count = 0;
		}

		java.lang.System.out.println(total);

	}

} public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		final int n = sc.nextInt();
		final int m = sc.nextInt();

		HashMap<Integer, ArrayList<Integer>> list = new HashMap<Integer, ArrayList<Integer>>();
		for (int i = 1; i <= n; i++) {
			int totalItem = sc.nextInt();
			ArrayList<Integer> itemList = new ArrayList<Integer>();
			for (int j = 0; j < totalItem; j++) {
				itemList.add(sc.nextInt());
			}
			list.put(i, itemList);
		}

		int count = 0;
		int total = 0;
		for (int k = 0; k <= m; k++) {
			for (final int key : list.keySet()) {
				final ArrayList<Integer> likeItem = list.get(key);
				if (likeItem.contains(k)) {
					count++;
				}
			}
			if (count == n) {
				total++;
			}
			count = 0;
		}

		java.lang.System.out.println(total);

	}

} Main
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		final int n = sc.nextInt();
		final int m = sc.nextInt();

		HashMap<Integer, ArrayList<Integer>> list = new HashMap<Integer, ArrayList<Integer>>();
		for (int i = 1; i <= n; i++) {
			int totalItem = sc.nextInt();
			ArrayList<Integer> itemList = new ArrayList<Integer>();
			for (int j = 0; j < totalItem; j++) {
				itemList.add(sc.nextInt());
			}
			list.put(i, itemList);
		}

		int count = 0;
		int total = 0;
		for (int k = 0; k <= m; k++) {
			for (final int key : list.keySet()) {
				final ArrayList<Integer> likeItem = list.get(key);
				if (likeItem.contains(k)) {
					count++;
				}
			}
			if (count == n) {
				total++;
			}
			count = 0;
		}

		java.lang.System.out.println(total);

	}

}
