import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] k = new int[n];
        int[][]a = new int[n][m];
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                a[i][j] = 0;
            }
        }
        int like = 0;
        for(int i=0; i<n; i++){
            k[i] = sc.nextInt();
            for(int j=0; j<k[i]; j++){
                like = sc.nextInt();
                a[i][like-1] = 1;
            }
        }
        int counter = 0;
        for(int j=0; j<m; j++){
            for(int i=0; i<n; i++){
                if(a[i][j] == 0){
                    break;
                }
                else if(i == n-1){
                    counter += 1;
                }
            }
        }
        System.out.println(counter);
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] k = new int[n];
        int[][]a = new int[n][m];
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                a[i][j] = 0;
            }
        }
        int like = 0;
        for(int i=0; i<n; i++){
            k[i] = sc.nextInt();
            for(int j=0; j<k[i]; j++){
                like = sc.nextInt();
                a[i][like-1] = 1;
            }
        }
        int counter = 0;
        for(int j=0; j<m; j++){
            for(int i=0; i<n; i++){
                if(a[i][j] == 0){
                    break;
                }
                else if(i == n-1){
                    counter += 1;
                }
            }
        }
        System.out.println(counter);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] k = new int[n];
        int[][]a = new int[n][m];
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                a[i][j] = 0;
            }
        }
        int like = 0;
        for(int i=0; i<n; i++){
            k[i] = sc.nextInt();
            for(int j=0; j<k[i]; j++){
                like = sc.nextInt();
                a[i][like-1] = 1;
            }
        }
        int counter = 0;
        for(int j=0; j<m; j++){
            for(int i=0; i<n; i++){
                if(a[i][j] == 0){
                    break;
                }
                else if(i == n-1){
                    counter += 1;
                }
            }
        }
        System.out.println(counter);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] k = new int[n];
        int[][]a = new int[n][m];
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                a[i][j] = 0;
            }
        }
        int like = 0;
        for(int i=0; i<n; i++){
            k[i] = sc.nextInt();
            for(int j=0; j<k[i]; j++){
                like = sc.nextInt();
                a[i][like-1] = 1;
            }
        }
        int counter = 0;
        for(int j=0; j<m; j++){
            for(int i=0; i<n; i++){
                if(a[i][j] == 0){
                    break;
                }
                else if(i == n-1){
                    counter += 1;
                }
            }
        }
        System.out.println(counter);
    } 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 int[] k = new int[n]; k new int[n] n int[][]a = new int[n][m]; a new int[n][m] n m for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                a[i][j] = 0;
            }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            for(int j=0; j<m; j++){
                a[i][j] = 0;
            }
        } {
            for(int j=0; j<m; j++){
                a[i][j] = 0;
            }
        } for(int j=0; j<m; j++){
                a[i][j] = 0;
            } int j=0; int j=0; j 0 j<m j m j++ j++ j {
                a[i][j] = 0;
            } {
                a[i][j] = 0;
            } a[i][j] = 0 a[i][j] a[i] a i j 0 int like = 0; like 0 for(int i=0; i<n; i++){
            k[i] = sc.nextInt();
            for(int j=0; j<k[i]; j++){
                like = sc.nextInt();
                a[i][like-1] = 1;
            }
        } 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++){
                like = sc.nextInt();
                a[i][like-1] = 1;
            }
        } {
            k[i] = sc.nextInt();
            for(int j=0; j<k[i]; j++){
                like = sc.nextInt();
                a[i][like-1] = 1;
            }
        } k[i] = sc.nextInt() k[i] k i sc.nextInt() sc.nextInt sc for(int j=0; j<k[i]; j++){
                like = sc.nextInt();
                a[i][like-1] = 1;
            } int j=0; int j=0; j 0 j<k[i] j k[i] k i j++ j++ j {
                like = sc.nextInt();
                a[i][like-1] = 1;
            } {
                like = sc.nextInt();
                a[i][like-1] = 1;
            } like = sc.nextInt() like sc.nextInt() sc.nextInt sc a[i][like-1] = 1 a[i][like-1] a[i] a i like-1 like 1 1 int counter = 0; counter 0 for(int j=0; j<m; j++){
            for(int i=0; i<n; i++){
                if(a[i][j] == 0){
                    break;
                }
                else if(i == n-1){
                    counter += 1;
                }
            }
        } int j=0; int j=0; j 0 j<m j m j++ j++ j {
            for(int i=0; i<n; i++){
                if(a[i][j] == 0){
                    break;
                }
                else if(i == n-1){
                    counter += 1;
                }
            }
        } {
            for(int i=0; i<n; i++){
                if(a[i][j] == 0){
                    break;
                }
                else if(i == n-1){
                    counter += 1;
                }
            }
        } for(int i=0; i<n; i++){
                if(a[i][j] == 0){
                    break;
                }
                else if(i == n-1){
                    counter += 1;
                }
            } int i=0; int i=0; i 0 i<n i n i++ i++ i {
                if(a[i][j] == 0){
                    break;
                }
                else if(i == n-1){
                    counter += 1;
                }
            } {
                if(a[i][j] == 0){
                    break;
                }
                else if(i == n-1){
                    counter += 1;
                }
            } if(a[i][j] == 0){
                    break;
                }
                else if(i == n-1){
                    counter += 1;
                } a[i][j] == 0 a[i][j] a[i] a i j 0 {
                    break;
                } break; if(i == n-1){
                    counter += 1;
                } i == n-1 i n-1 n 1 {
                    counter += 1;
                } counter += 1 counter 1 System.out.println(counter) System.out.println System.out System System.out counter String[] args args public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] k = new int[n];
        int[][]a = new int[n][m];
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                a[i][j] = 0;
            }
        }
        int like = 0;
        for(int i=0; i<n; i++){
            k[i] = sc.nextInt();
            for(int j=0; j<k[i]; j++){
                like = sc.nextInt();
                a[i][like-1] = 1;
            }
        }
        int counter = 0;
        for(int j=0; j<m; j++){
            for(int i=0; i<n; i++){
                if(a[i][j] == 0){
                    break;
                }
                else if(i == n-1){
                    counter += 1;
                }
            }
        }
        System.out.println(counter);
    }
} public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] k = new int[n];
        int[][]a = new int[n][m];
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                a[i][j] = 0;
            }
        }
        int like = 0;
        for(int i=0; i<n; i++){
            k[i] = sc.nextInt();
            for(int j=0; j<k[i]; j++){
                like = sc.nextInt();
                a[i][like-1] = 1;
            }
        }
        int counter = 0;
        for(int j=0; j<m; j++){
            for(int i=0; i<n; i++){
                if(a[i][j] == 0){
                    break;
                }
                else if(i == n-1){
                    counter += 1;
                }
            }
        }
        System.out.println(counter);
    }
} Main
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] k = new int[n];
        int[][]a = new int[n][m];
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                a[i][j] = 0;
            }
        }
        int like = 0;
        for(int i=0; i<n; i++){
            k[i] = sc.nextInt();
            for(int j=0; j<k[i]; j++){
                like = sc.nextInt();
                a[i][like-1] = 1;
            }
        }
        int counter = 0;
        for(int j=0; j<m; j++){
            for(int i=0; i<n; i++){
                if(a[i][j] == 0){
                    break;
                }
                else if(i == n-1){
                    counter += 1;
                }
            }
        }
        System.out.println(counter);
    }
}