import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Integer[][] a = new Integer[N][M];
		for (int i=0;i<N;i++) {
			int K = sc.nextInt();
			Integer[] b = new Integer[K];
			for (int x=0;x<K;x++) {
				b[x]=sc.nextInt();
			}
			a[i]=b;
		}
		int len = a[0].length;
		int cnt = 0;
		for (int i=0;i<len;i++) {
			for (int k=0;k<N;k++) {
				if (Arrays.asList(a[k]).contains(a[0][i])) {
					if (k==N-1) {
						cnt++;
					}
				}else {
					break;
				}
			}
		}
		System.out.println(cnt);
	}
} import java.util.*; util.* java class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Integer[][] a = new Integer[N][M];
		for (int i=0;i<N;i++) {
			int K = sc.nextInt();
			Integer[] b = new Integer[K];
			for (int x=0;x<K;x++) {
				b[x]=sc.nextInt();
			}
			a[i]=b;
		}
		int len = a[0].length;
		int cnt = 0;
		for (int i=0;i<len;i++) {
			for (int k=0;k<N;k++) {
				if (Arrays.asList(a[k]).contains(a[0][i])) {
					if (k==N-1) {
						cnt++;
					}
				}else {
					break;
				}
			}
		}
		System.out.println(cnt);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Integer[][] a = new Integer[N][M];
		for (int i=0;i<N;i++) {
			int K = sc.nextInt();
			Integer[] b = new Integer[K];
			for (int x=0;x<K;x++) {
				b[x]=sc.nextInt();
			}
			a[i]=b;
		}
		int len = a[0].length;
		int cnt = 0;
		for (int i=0;i<len;i++) {
			for (int k=0;k<N;k++) {
				if (Arrays.asList(a[k]).contains(a[0][i])) {
					if (k==N-1) {
						cnt++;
					}
				}else {
					break;
				}
			}
		}
		System.out.println(cnt);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Integer[][] a = new Integer[N][M];
		for (int i=0;i<N;i++) {
			int K = sc.nextInt();
			Integer[] b = new Integer[K];
			for (int x=0;x<K;x++) {
				b[x]=sc.nextInt();
			}
			a[i]=b;
		}
		int len = a[0].length;
		int cnt = 0;
		for (int i=0;i<len;i++) {
			for (int k=0;k<N;k++) {
				if (Arrays.asList(a[k]).contains(a[0][i])) {
					if (k==N-1) {
						cnt++;
					}
				}else {
					break;
				}
			}
		}
		System.out.println(cnt);
	} 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 Integer[][] a = new Integer[N][M]; a new Integer[N][M] N M for (int i=0;i<N;i++) {
			int K = sc.nextInt();
			Integer[] b = new Integer[K];
			for (int x=0;x<K;x++) {
				b[x]=sc.nextInt();
			}
			a[i]=b;
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			int K = sc.nextInt();
			Integer[] b = new Integer[K];
			for (int x=0;x<K;x++) {
				b[x]=sc.nextInt();
			}
			a[i]=b;
		} {
			int K = sc.nextInt();
			Integer[] b = new Integer[K];
			for (int x=0;x<K;x++) {
				b[x]=sc.nextInt();
			}
			a[i]=b;
		} int K = sc.nextInt(); K sc.nextInt() sc.nextInt sc Integer[] b = new Integer[K]; b new Integer[K] K for (int x=0;x<K;x++) {
				b[x]=sc.nextInt();
			} int x=0; int x=0; x 0 x<K x K x++ x++ x {
				b[x]=sc.nextInt();
			} {
				b[x]=sc.nextInt();
			} b[x]=sc.nextInt() b[x] b x sc.nextInt() sc.nextInt sc a[i]=b a[i] a i b int len = a[0].length; len a[0].length a[0] a 0 a[0].length int cnt = 0; cnt 0 for (int i=0;i<len;i++) {
			for (int k=0;k<N;k++) {
				if (Arrays.asList(a[k]).contains(a[0][i])) {
					if (k==N-1) {
						cnt++;
					}
				}else {
					break;
				}
			}
		} int i=0; int i=0; i 0 i<len i len i++ i++ i {
			for (int k=0;k<N;k++) {
				if (Arrays.asList(a[k]).contains(a[0][i])) {
					if (k==N-1) {
						cnt++;
					}
				}else {
					break;
				}
			}
		} {
			for (int k=0;k<N;k++) {
				if (Arrays.asList(a[k]).contains(a[0][i])) {
					if (k==N-1) {
						cnt++;
					}
				}else {
					break;
				}
			}
		} for (int k=0;k<N;k++) {
				if (Arrays.asList(a[k]).contains(a[0][i])) {
					if (k==N-1) {
						cnt++;
					}
				}else {
					break;
				}
			} int k=0; int k=0; k 0 k<N k N k++ k++ k {
				if (Arrays.asList(a[k]).contains(a[0][i])) {
					if (k==N-1) {
						cnt++;
					}
				}else {
					break;
				}
			} {
				if (Arrays.asList(a[k]).contains(a[0][i])) {
					if (k==N-1) {
						cnt++;
					}
				}else {
					break;
				}
			} if (Arrays.asList(a[k]).contains(a[0][i])) {
					if (k==N-1) {
						cnt++;
					}
				}else {
					break;
				} Arrays.asList(a[k]).contains(a[0][i]) Arrays.asList(a[k]).contains Arrays.asList(a[k]) Arrays.asList Arrays a[k] a k a[0][i] a[0] a 0 i {
					if (k==N-1) {
						cnt++;
					}
				} if (k==N-1) {
						cnt++;
					} k==N-1 k N-1 N 1 {
						cnt++;
					} cnt++ cnt {
					break;
				} break; System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Integer[][] a = new Integer[N][M];
		for (int i=0;i<N;i++) {
			int K = sc.nextInt();
			Integer[] b = new Integer[K];
			for (int x=0;x<K;x++) {
				b[x]=sc.nextInt();
			}
			a[i]=b;
		}
		int len = a[0].length;
		int cnt = 0;
		for (int i=0;i<len;i++) {
			for (int k=0;k<N;k++) {
				if (Arrays.asList(a[k]).contains(a[0][i])) {
					if (k==N-1) {
						cnt++;
					}
				}else {
					break;
				}
			}
		}
		System.out.println(cnt);
	}
}