import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] count = new int[m];
        int k;
        int A;
        for(int i=0;i<n;i++){
            k = Integer.parseInt(sc.next());
            for(int j=0;j<k;j++){
                A = Integer.parseInt(sc.next())-1;
                count[A]++;
            }
        }
        int res = 0;
        for(int i=0;i<m;i++){
            if(count[i]==n)res++;
        }
        System.out.println(res);
        sc.close();
    }
    
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] count = new int[m];
        int k;
        int A;
        for(int i=0;i<n;i++){
            k = Integer.parseInt(sc.next());
            for(int j=0;j<k;j++){
                A = Integer.parseInt(sc.next())-1;
                count[A]++;
            }
        }
        int res = 0;
        for(int i=0;i<m;i++){
            if(count[i]==n)res++;
        }
        System.out.println(res);
        sc.close();
    }
    
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] count = new int[m];
        int k;
        int A;
        for(int i=0;i<n;i++){
            k = Integer.parseInt(sc.next());
            for(int j=0;j<k;j++){
                A = Integer.parseInt(sc.next())-1;
                count[A]++;
            }
        }
        int res = 0;
        for(int i=0;i<m;i++){
            if(count[i]==n)res++;
        }
        System.out.println(res);
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] count = new int[m];
        int k;
        int A;
        for(int i=0;i<n;i++){
            k = Integer.parseInt(sc.next());
            for(int j=0;j<k;j++){
                A = Integer.parseInt(sc.next())-1;
                count[A]++;
            }
        }
        int res = 0;
        for(int i=0;i<m;i++){
            if(count[i]==n)res++;
        }
        System.out.println(res);
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int m = Integer.parseInt(sc.next()); m Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] count = new int[m]; count new int[m] m int k; k int A; A for(int i=0;i<n;i++){
            k = Integer.parseInt(sc.next());
            for(int j=0;j<k;j++){
                A = Integer.parseInt(sc.next())-1;
                count[A]++;
            }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            k = Integer.parseInt(sc.next());
            for(int j=0;j<k;j++){
                A = Integer.parseInt(sc.next())-1;
                count[A]++;
            }
        } {
            k = Integer.parseInt(sc.next());
            for(int j=0;j<k;j++){
                A = Integer.parseInt(sc.next())-1;
                count[A]++;
            }
        } k = Integer.parseInt(sc.next()) k Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc for(int j=0;j<k;j++){
                A = Integer.parseInt(sc.next())-1;
                count[A]++;
            } int j=0; int j=0; j 0 j<k j k j++ j++ j {
                A = Integer.parseInt(sc.next())-1;
                count[A]++;
            } {
                A = Integer.parseInt(sc.next())-1;
                count[A]++;
            } A = Integer.parseInt(sc.next())-1 A Integer.parseInt(sc.next())-1 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc 1 count[A]++ count[A] count A int res = 0; res 0 for(int i=0;i<m;i++){
            if(count[i]==n)res++;
        } int i=0; int i=0; i 0 i<m i m i++ i++ i {
            if(count[i]==n)res++;
        } {
            if(count[i]==n)res++;
        } if(count[i]==n)res++; count[i]==n count[i] count i n res++ res System.out.println(res) System.out.println System.out System System.out res sc.close() sc.close sc String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] count = new int[m];
        int k;
        int A;
        for(int i=0;i<n;i++){
            k = Integer.parseInt(sc.next());
            for(int j=0;j<k;j++){
                A = Integer.parseInt(sc.next())-1;
                count[A]++;
            }
        }
        int res = 0;
        for(int i=0;i<m;i++){
            if(count[i]==n)res++;
        }
        System.out.println(res);
        sc.close();
    }
    
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] count = new int[m];
        int k;
        int A;
        for(int i=0;i<n;i++){
            k = Integer.parseInt(sc.next());
            for(int j=0;j<k;j++){
                A = Integer.parseInt(sc.next())-1;
                count[A]++;
            }
        }
        int res = 0;
        for(int i=0;i<m;i++){
            if(count[i]==n)res++;
        }
        System.out.println(res);
        sc.close();
    }
    
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] count = new int[m];
        int k;
        int A;
        for(int i=0;i<n;i++){
            k = Integer.parseInt(sc.next());
            for(int j=0;j<k;j++){
                A = Integer.parseInt(sc.next())-1;
                count[A]++;
            }
        }
        int res = 0;
        for(int i=0;i<m;i++){
            if(count[i]==n)res++;
        }
        System.out.println(res);
        sc.close();
    }
    
}