import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Calc c = new Calc();
		c.abc118B();
	}
}

class Calc{
  void abc118B() {
		Scanner sc = new Scanner(System.in);
		int like=0, cnt=0;
		boolean check = false;
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] k = new int[n];
		int[][] food = new int[n][30];
		for(int i=0 ; i<n ; i++) {
			k[i] = sc.nextInt();
			for(int j=0 ; j<k[i] ; j++) {
				food[i][j] = sc.nextInt();
			}
		}
		for(int i=1 ; i<=m ; i++) {
			//縦列
			for(int j=0 ; j<n ; j++) {
				//横一列
				for(int p=0 ; p<k[j] ; p++) {
					if( i == food[j][p] ) {
						like ++;
					}
				}
			}
			if(like == n) {
				cnt++;
			}
			like = 0;
		}
		System.out.println(cnt);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Calc c = new Calc();
		c.abc118B();
	}
} Main public static void main(String[] args) {
		Calc c = new Calc();
		c.abc118B();
	} main {
		Calc c = new Calc();
		c.abc118B();
	} Calc c = new Calc(); c new Calc() c.abc118B() c.abc118B c String[] args args class Calc{
  void abc118B() {
		Scanner sc = new Scanner(System.in);
		int like=0, cnt=0;
		boolean check = false;
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] k = new int[n];
		int[][] food = new int[n][30];
		for(int i=0 ; i<n ; i++) {
			k[i] = sc.nextInt();
			for(int j=0 ; j<k[i] ; j++) {
				food[i][j] = sc.nextInt();
			}
		}
		for(int i=1 ; i<=m ; i++) {
			//縦列
			for(int j=0 ; j<n ; j++) {
				//横一列
				for(int p=0 ; p<k[j] ; p++) {
					if( i == food[j][p] ) {
						like ++;
					}
				}
			}
			if(like == n) {
				cnt++;
			}
			like = 0;
		}
		System.out.println(cnt);
	}
} Calc void abc118B() {
		Scanner sc = new Scanner(System.in);
		int like=0, cnt=0;
		boolean check = false;
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] k = new int[n];
		int[][] food = new int[n][30];
		for(int i=0 ; i<n ; i++) {
			k[i] = sc.nextInt();
			for(int j=0 ; j<k[i] ; j++) {
				food[i][j] = sc.nextInt();
			}
		}
		for(int i=1 ; i<=m ; i++) {
			//縦列
			for(int j=0 ; j<n ; j++) {
				//横一列
				for(int p=0 ; p<k[j] ; p++) {
					if( i == food[j][p] ) {
						like ++;
					}
				}
			}
			if(like == n) {
				cnt++;
			}
			like = 0;
		}
		System.out.println(cnt);
	} abc118B {
		Scanner sc = new Scanner(System.in);
		int like=0, cnt=0;
		boolean check = false;
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] k = new int[n];
		int[][] food = new int[n][30];
		for(int i=0 ; i<n ; i++) {
			k[i] = sc.nextInt();
			for(int j=0 ; j<k[i] ; j++) {
				food[i][j] = sc.nextInt();
			}
		}
		for(int i=1 ; i<=m ; i++) {
			//縦列
			for(int j=0 ; j<n ; j++) {
				//横一列
				for(int p=0 ; p<k[j] ; p++) {
					if( i == food[j][p] ) {
						like ++;
					}
				}
			}
			if(like == n) {
				cnt++;
			}
			like = 0;
		}
		System.out.println(cnt);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int like=0 like 0 cnt=0; cnt 0 boolean check = false; check false int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int[] k = new int[n]; k new int[n] n int[][] food = new int[n][30]; food new int[n][30] n 30 for(int i=0 ; i<n ; i++) {
			k[i] = sc.nextInt();
			for(int j=0 ; j<k[i] ; j++) {
				food[i][j] = sc.nextInt();
			}
		} int i=0 ; int i=0 ; i 0 i<n i n i++ i++ i {
			k[i] = sc.nextInt();
			for(int j=0 ; j<k[i] ; j++) {
				food[i][j] = sc.nextInt();
			}
		} {
			k[i] = sc.nextInt();
			for(int j=0 ; j<k[i] ; j++) {
				food[i][j] = sc.nextInt();
			}
		} k[i] = sc.nextInt() k[i] k i sc.nextInt() sc.nextInt sc for(int j=0 ; j<k[i] ; j++) {
				food[i][j] = sc.nextInt();
			} int j=0 ; int j=0 ; j 0 j<k[i] j k[i] k i j++ j++ j {
				food[i][j] = sc.nextInt();
			} {
				food[i][j] = sc.nextInt();
			} food[i][j] = sc.nextInt() food[i][j] food[i] food i j sc.nextInt() sc.nextInt sc for(int i=1 ; i<=m ; i++) {
			//縦列
			for(int j=0 ; j<n ; j++) {
				//横一列
				for(int p=0 ; p<k[j] ; p++) {
					if( i == food[j][p] ) {
						like ++;
					}
				}
			}
			if(like == n) {
				cnt++;
			}
			like = 0;
		} int i=1 ; int i=1 ; i 1 i<=m i m i++ i++ i {
			//縦列
			for(int j=0 ; j<n ; j++) {
				//横一列
				for(int p=0 ; p<k[j] ; p++) {
					if( i == food[j][p] ) {
						like ++;
					}
				}
			}
			if(like == n) {
				cnt++;
			}
			like = 0;
		} {
			//縦列
			for(int j=0 ; j<n ; j++) {
				//横一列
				for(int p=0 ; p<k[j] ; p++) {
					if( i == food[j][p] ) {
						like ++;
					}
				}
			}
			if(like == n) {
				cnt++;
			}
			like = 0;
		} for(int j=0 ; j<n ; j++) {
				//横一列
				for(int p=0 ; p<k[j] ; p++) {
					if( i == food[j][p] ) {
						like ++;
					}
				}
			} int j=0 ; int j=0 ; j 0 j<n j n j++ j++ j {
				//横一列
				for(int p=0 ; p<k[j] ; p++) {
					if( i == food[j][p] ) {
						like ++;
					}
				}
			} {
				//横一列
				for(int p=0 ; p<k[j] ; p++) {
					if( i == food[j][p] ) {
						like ++;
					}
				}
			} for(int p=0 ; p<k[j] ; p++) {
					if( i == food[j][p] ) {
						like ++;
					}
				} int p=0 ; int p=0 ; p 0 p<k[j] p k[j] k j p++ p++ p {
					if( i == food[j][p] ) {
						like ++;
					}
				} {
					if( i == food[j][p] ) {
						like ++;
					}
				} if( i == food[j][p] ) {
						like ++;
					} i == food[j][p] i food[j][p] food[j] food j p {
						like ++;
					} like ++ like if(like == n) {
				cnt++;
			} like == n like n {
				cnt++;
			} cnt++ cnt like = 0 like 0 System.out.println(cnt) System.out.println System.out System System.out cnt public class Main {
	public static void main(String[] args) {
		Calc c = new Calc();
		c.abc118B();
	}
} public class Main {
	public static void main(String[] args) {
		Calc c = new Calc();
		c.abc118B();
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Calc c = new Calc();
		c.abc118B();
	}
}

class Calc{
  void abc118B() {
		Scanner sc = new Scanner(System.in);
		int like=0, cnt=0;
		boolean check = false;
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] k = new int[n];
		int[][] food = new int[n][30];
		for(int i=0 ; i<n ; i++) {
			k[i] = sc.nextInt();
			for(int j=0 ; j<k[i] ; j++) {
				food[i][j] = sc.nextInt();
			}
		}
		for(int i=1 ; i<=m ; i++) {
			//縦列
			for(int j=0 ; j<n ; j++) {
				//横一列
				for(int p=0 ; p<k[j] ; p++) {
					if( i == food[j][p] ) {
						like ++;
					}
				}
			}
			if(like == n) {
				cnt++;
			}
			like = 0;
		}
		System.out.println(cnt);
	}
}