import java.io.*;
import java.util.*;
class Program{

}
class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String ip[];
        int i,no,N = in.nextInt(); int M = in.nextInt();
        boolean K[][]= new boolean[N][M];
        for(int n = 0;n<N;n++){
            no = in.nextInt();
            while(no-->0){
                K[n][in.nextInt()-1] = true;
            }
        }
        //for(boolean[] var: K) System.out.println(Arrays.toString(var));
        int count = 0,local=0;
        for(i =0;i<M;i++){
            local = 0;
            for(int j=0;j<N;j++){
                if (!K[j][i]){
                    break;
                }
                local++; 
            }
            if (local==N) count++;
        }
        System.out.println(count);
    }
} import java.io.*; io.* java import java.util.*; util.* java class Program{

} Program class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String ip[];
        int i,no,N = in.nextInt(); int M = in.nextInt();
        boolean K[][]= new boolean[N][M];
        for(int n = 0;n<N;n++){
            no = in.nextInt();
            while(no-->0){
                K[n][in.nextInt()-1] = true;
            }
        }
        //for(boolean[] var: K) System.out.println(Arrays.toString(var));
        int count = 0,local=0;
        for(i =0;i<M;i++){
            local = 0;
            for(int j=0;j<N;j++){
                if (!K[j][i]){
                    break;
                }
                local++; 
            }
            if (local==N) count++;
        }
        System.out.println(count);
    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String ip[];
        int i,no,N = in.nextInt(); int M = in.nextInt();
        boolean K[][]= new boolean[N][M];
        for(int n = 0;n<N;n++){
            no = in.nextInt();
            while(no-->0){
                K[n][in.nextInt()-1] = true;
            }
        }
        //for(boolean[] var: K) System.out.println(Arrays.toString(var));
        int count = 0,local=0;
        for(i =0;i<M;i++){
            local = 0;
            for(int j=0;j<N;j++){
                if (!K[j][i]){
                    break;
                }
                local++; 
            }
            if (local==N) count++;
        }
        System.out.println(count);
    } main {
        Scanner in = new Scanner(System.in);
        String ip[];
        int i,no,N = in.nextInt(); int M = in.nextInt();
        boolean K[][]= new boolean[N][M];
        for(int n = 0;n<N;n++){
            no = in.nextInt();
            while(no-->0){
                K[n][in.nextInt()-1] = true;
            }
        }
        //for(boolean[] var: K) System.out.println(Arrays.toString(var));
        int count = 0,local=0;
        for(i =0;i<M;i++){
            local = 0;
            for(int j=0;j<N;j++){
                if (!K[j][i]){
                    break;
                }
                local++; 
            }
            if (local==N) count++;
        }
        System.out.println(count);
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) String ip[]; ip int i i no no N = in.nextInt(); N in.nextInt() in.nextInt in int M = in.nextInt(); M in.nextInt() in.nextInt in boolean K[][]= new boolean[N][M]; K new boolean[N][M] N M for(int n = 0;n<N;n++){
            no = in.nextInt();
            while(no-->0){
                K[n][in.nextInt()-1] = true;
            }
        } int n = 0; int n = 0; n 0 n<N n N n++ n++ n {
            no = in.nextInt();
            while(no-->0){
                K[n][in.nextInt()-1] = true;
            }
        } {
            no = in.nextInt();
            while(no-->0){
                K[n][in.nextInt()-1] = true;
            }
        } no = in.nextInt() no in.nextInt() in.nextInt in while(no-->0){
                K[n][in.nextInt()-1] = true;
            } no-->0 no-- no 0 {
                K[n][in.nextInt()-1] = true;
            } K[n][in.nextInt()-1] = true K[n][in.nextInt()-1] K[n] K n in.nextInt()-1 in.nextInt() in.nextInt in 1 true int count = 0 count 0 local=0; local 0 for(i =0;i<M;i++){
            local = 0;
            for(int j=0;j<N;j++){
                if (!K[j][i]){
                    break;
                }
                local++; 
            }
            if (local==N) count++;
        } i =0; i =0 i 0 i<M i M i++ i++ i {
            local = 0;
            for(int j=0;j<N;j++){
                if (!K[j][i]){
                    break;
                }
                local++; 
            }
            if (local==N) count++;
        } {
            local = 0;
            for(int j=0;j<N;j++){
                if (!K[j][i]){
                    break;
                }
                local++; 
            }
            if (local==N) count++;
        } local = 0 local 0 for(int j=0;j<N;j++){
                if (!K[j][i]){
                    break;
                }
                local++; 
            } int j=0; int j=0; j 0 j<N j N j++ j++ j {
                if (!K[j][i]){
                    break;
                }
                local++; 
            } {
                if (!K[j][i]){
                    break;
                }
                local++; 
            } if (!K[j][i]){
                    break;
                } !K[j][i] K[j][i] K[j] K j i {
                    break;
                } break; local++ local if (local==N) count++; local==N local N count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.io.*;
import java.util.*;
class Program{

}
class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String ip[];
        int i,no,N = in.nextInt(); int M = in.nextInt();
        boolean K[][]= new boolean[N][M];
        for(int n = 0;n<N;n++){
            no = in.nextInt();
            while(no-->0){
                K[n][in.nextInt()-1] = true;
            }
        }
        //for(boolean[] var: K) System.out.println(Arrays.toString(var));
        int count = 0,local=0;
        for(i =0;i<M;i++){
            local = 0;
            for(int j=0;j<N;j++){
                if (!K[j][i]){
                    break;
                }
                local++; 
            }
            if (local==N) count++;
        }
        System.out.println(count);
    }
}