import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int[] f = new int[b];
		for(int i=0;i<a;i++){
			int c = scan.nextInt();
			for(int l=0;l<c;l++){
				int d = scan.nextInt();
				f[d-1]++;
			}
		}
		int ans=0;
		Arrays.sort(f);
		for(int i=b-1;i>=0;i--){
			if(f[i]!=a){break;}else{ans++;}
		}
		System.out.println(ans);
	}
} import java.util.*; util.* java public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int[] f = new int[b];
		for(int i=0;i<a;i++){
			int c = scan.nextInt();
			for(int l=0;l<c;l++){
				int d = scan.nextInt();
				f[d-1]++;
			}
		}
		int ans=0;
		Arrays.sort(f);
		for(int i=b-1;i>=0;i--){
			if(f[i]!=a){break;}else{ans++;}
		}
		System.out.println(ans);
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int[] f = new int[b];
		for(int i=0;i<a;i++){
			int c = scan.nextInt();
			for(int l=0;l<c;l++){
				int d = scan.nextInt();
				f[d-1]++;
			}
		}
		int ans=0;
		Arrays.sort(f);
		for(int i=b-1;i>=0;i--){
			if(f[i]!=a){break;}else{ans++;}
		}
		System.out.println(ans);
	} main {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int[] f = new int[b];
		for(int i=0;i<a;i++){
			int c = scan.nextInt();
			for(int l=0;l<c;l++){
				int d = scan.nextInt();
				f[d-1]++;
			}
		}
		int ans=0;
		Arrays.sort(f);
		for(int i=b-1;i>=0;i--){
			if(f[i]!=a){break;}else{ans++;}
		}
		System.out.println(ans);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int a = scan.nextInt(); a scan.nextInt() scan.nextInt scan int b = scan.nextInt(); b scan.nextInt() scan.nextInt scan int[] f = new int[b]; f new int[b] b for(int i=0;i<a;i++){
			int c = scan.nextInt();
			for(int l=0;l<c;l++){
				int d = scan.nextInt();
				f[d-1]++;
			}
		} int i=0; int i=0; i 0 i<a i a i++ i++ i {
			int c = scan.nextInt();
			for(int l=0;l<c;l++){
				int d = scan.nextInt();
				f[d-1]++;
			}
		} {
			int c = scan.nextInt();
			for(int l=0;l<c;l++){
				int d = scan.nextInt();
				f[d-1]++;
			}
		} int c = scan.nextInt(); c scan.nextInt() scan.nextInt scan for(int l=0;l<c;l++){
				int d = scan.nextInt();
				f[d-1]++;
			} int l=0; int l=0; l 0 l<c l c l++ l++ l {
				int d = scan.nextInt();
				f[d-1]++;
			} {
				int d = scan.nextInt();
				f[d-1]++;
			} int d = scan.nextInt(); d scan.nextInt() scan.nextInt scan f[d-1]++ f[d-1] f d-1 d 1 int ans=0; ans 0 Arrays.sort(f) Arrays.sort Arrays f for(int i=b-1;i>=0;i--){
			if(f[i]!=a){break;}else{ans++;}
		} int i=b-1; int i=b-1; i b-1 b 1 i>=0 i 0 i-- i-- i {
			if(f[i]!=a){break;}else{ans++;}
		} {
			if(f[i]!=a){break;}else{ans++;}
		} if(f[i]!=a){break;}else{ans++;} f[i]!=a f[i] f i a {break;} break; {ans++;} ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int[] f = new int[b];
		for(int i=0;i<a;i++){
			int c = scan.nextInt();
			for(int l=0;l<c;l++){
				int d = scan.nextInt();
				f[d-1]++;
			}
		}
		int ans=0;
		Arrays.sort(f);
		for(int i=b-1;i>=0;i--){
			if(f[i]!=a){break;}else{ans++;}
		}
		System.out.println(ans);
	}
} public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int[] f = new int[b];
		for(int i=0;i<a;i++){
			int c = scan.nextInt();
			for(int l=0;l<c;l++){
				int d = scan.nextInt();
				f[d-1]++;
			}
		}
		int ans=0;
		Arrays.sort(f);
		for(int i=b-1;i>=0;i--){
			if(f[i]!=a){break;}else{ans++;}
		}
		System.out.println(ans);
	}
} Main
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int[] f = new int[b];
		for(int i=0;i<a;i++){
			int c = scan.nextInt();
			for(int l=0;l<c;l++){
				int d = scan.nextInt();
				f[d-1]++;
			}
		}
		int ans=0;
		Arrays.sort(f);
		for(int i=b-1;i>=0;i--){
			if(f[i]!=a){break;}else{ans++;}
		}
		System.out.println(ans);
	}
}