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 tmpk;
        boolean[][] nums = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            tmpk = sc.nextInt();
            for (int j = 0; j < tmpk; j++) {
                nums[i][sc.nextInt() - 1] = true;
            }

        }
        boolean b;
        int output=0;
        for(int i=0;i<m;i++){
            b=true;
            for(int j=0;j<n;j++){
                if(!nums[j][i]){
                    b=false;
                }
            }
            if(b){
                output++;
            }
        }
        System.out.println(output);

    }
} 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 tmpk;
        boolean[][] nums = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            tmpk = sc.nextInt();
            for (int j = 0; j < tmpk; j++) {
                nums[i][sc.nextInt() - 1] = true;
            }

        }
        boolean b;
        int output=0;
        for(int i=0;i<m;i++){
            b=true;
            for(int j=0;j<n;j++){
                if(!nums[j][i]){
                    b=false;
                }
            }
            if(b){
                output++;
            }
        }
        System.out.println(output);

    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int tmpk;
        boolean[][] nums = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            tmpk = sc.nextInt();
            for (int j = 0; j < tmpk; j++) {
                nums[i][sc.nextInt() - 1] = true;
            }

        }
        boolean b;
        int output=0;
        for(int i=0;i<m;i++){
            b=true;
            for(int j=0;j<n;j++){
                if(!nums[j][i]){
                    b=false;
                }
            }
            if(b){
                output++;
            }
        }
        System.out.println(output);

    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int tmpk;
        boolean[][] nums = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            tmpk = sc.nextInt();
            for (int j = 0; j < tmpk; j++) {
                nums[i][sc.nextInt() - 1] = true;
            }

        }
        boolean b;
        int output=0;
        for(int i=0;i<m;i++){
            b=true;
            for(int j=0;j<n;j++){
                if(!nums[j][i]){
                    b=false;
                }
            }
            if(b){
                output++;
            }
        }
        System.out.println(output);

    } 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 tmpk; tmpk boolean[][] nums = new boolean[n][m]; nums new boolean[n][m] n m for (int i = 0; i < n; i++) {
            tmpk = sc.nextInt();
            for (int j = 0; j < tmpk; j++) {
                nums[i][sc.nextInt() - 1] = true;
            }

        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            tmpk = sc.nextInt();
            for (int j = 0; j < tmpk; j++) {
                nums[i][sc.nextInt() - 1] = true;
            }

        } {
            tmpk = sc.nextInt();
            for (int j = 0; j < tmpk; j++) {
                nums[i][sc.nextInt() - 1] = true;
            }

        } tmpk = sc.nextInt() tmpk sc.nextInt() sc.nextInt sc for (int j = 0; j < tmpk; j++) {
                nums[i][sc.nextInt() - 1] = true;
            } int j = 0; int j = 0; j 0 j < tmpk j tmpk j++ j++ j {
                nums[i][sc.nextInt() - 1] = true;
            } {
                nums[i][sc.nextInt() - 1] = true;
            } nums[i][sc.nextInt() - 1] = true nums[i][sc.nextInt() - 1] nums[i] nums i sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 true boolean b; b int output=0; output 0 for(int i=0;i<m;i++){
            b=true;
            for(int j=0;j<n;j++){
                if(!nums[j][i]){
                    b=false;
                }
            }
            if(b){
                output++;
            }
        } int i=0; int i=0; i 0 i<m i m i++ i++ i {
            b=true;
            for(int j=0;j<n;j++){
                if(!nums[j][i]){
                    b=false;
                }
            }
            if(b){
                output++;
            }
        } {
            b=true;
            for(int j=0;j<n;j++){
                if(!nums[j][i]){
                    b=false;
                }
            }
            if(b){
                output++;
            }
        } b=true b true for(int j=0;j<n;j++){
                if(!nums[j][i]){
                    b=false;
                }
            } int j=0; int j=0; j 0 j<n j n j++ j++ j {
                if(!nums[j][i]){
                    b=false;
                }
            } {
                if(!nums[j][i]){
                    b=false;
                }
            } if(!nums[j][i]){
                    b=false;
                } !nums[j][i] nums[j][i] nums[j] nums j i {
                    b=false;
                } b=false b false if(b){
                output++;
            } b {
                output++;
            } output++ output System.out.println(output) System.out.println System.out System System.out output 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 tmpk;
        boolean[][] nums = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            tmpk = sc.nextInt();
            for (int j = 0; j < tmpk; j++) {
                nums[i][sc.nextInt() - 1] = true;
            }

        }
        boolean b;
        int output=0;
        for(int i=0;i<m;i++){
            b=true;
            for(int j=0;j<n;j++){
                if(!nums[j][i]){
                    b=false;
                }
            }
            if(b){
                output++;
            }
        }
        System.out.println(output);

    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int tmpk;
        boolean[][] nums = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            tmpk = sc.nextInt();
            for (int j = 0; j < tmpk; j++) {
                nums[i][sc.nextInt() - 1] = true;
            }

        }
        boolean b;
        int output=0;
        for(int i=0;i<m;i++){
            b=true;
            for(int j=0;j<n;j++){
                if(!nums[j][i]){
                    b=false;
                }
            }
            if(b){
                output++;
            }
        }
        System.out.println(output);

    }
} 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 tmpk;
        boolean[][] nums = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            tmpk = sc.nextInt();
            for (int j = 0; j < tmpk; j++) {
                nums[i][sc.nextInt() - 1] = true;
            }

        }
        boolean b;
        int output=0;
        for(int i=0;i<m;i++){
            b=true;
            for(int j=0;j<n;j++){
                if(!nums[j][i]){
                    b=false;
                }
            }
            if(b){
                output++;
            }
        }
        System.out.println(output);

    }
}