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];
        int x = 1;
        int ans = 0;

        for(int i=0; i<N; i++){
            K[i] = sc.nextInt();
            for(int j=0; j<K[i]; j++){
                A[i][j] = sc.nextInt();
            }
        }
        if(N>1){
            for(int i=0; i<M; i++){
                loop:for(int j=1; j<N; j++){
                    for(int k=0; k<K[j]; k++){
                        if(A[0][i]==A[j][k]){
                            x += 1;
                            break;
                        }
                        else if(A[0][i]!=A[j][M-1] && k==M-1){
                            x = 0;
                            break loop;
                        }
                    }
                }
                if(x==N){
                    ans += 1;
                }
                x = 1;
            }
        }
        if(N==1){
            ans = K[0];
        }
        System.out.println(ans);
    }
} 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];
        int x = 1;
        int ans = 0;

        for(int i=0; i<N; i++){
            K[i] = sc.nextInt();
            for(int j=0; j<K[i]; j++){
                A[i][j] = sc.nextInt();
            }
        }
        if(N>1){
            for(int i=0; i<M; i++){
                loop:for(int j=1; j<N; j++){
                    for(int k=0; k<K[j]; k++){
                        if(A[0][i]==A[j][k]){
                            x += 1;
                            break;
                        }
                        else if(A[0][i]!=A[j][M-1] && k==M-1){
                            x = 0;
                            break loop;
                        }
                    }
                }
                if(x==N){
                    ans += 1;
                }
                x = 1;
            }
        }
        if(N==1){
            ans = K[0];
        }
        System.out.println(ans);
    }
} 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];
        int x = 1;
        int ans = 0;

        for(int i=0; i<N; i++){
            K[i] = sc.nextInt();
            for(int j=0; j<K[i]; j++){
                A[i][j] = sc.nextInt();
            }
        }
        if(N>1){
            for(int i=0; i<M; i++){
                loop:for(int j=1; j<N; j++){
                    for(int k=0; k<K[j]; k++){
                        if(A[0][i]==A[j][k]){
                            x += 1;
                            break;
                        }
                        else if(A[0][i]!=A[j][M-1] && k==M-1){
                            x = 0;
                            break loop;
                        }
                    }
                }
                if(x==N){
                    ans += 1;
                }
                x = 1;
            }
        }
        if(N==1){
            ans = K[0];
        }
        System.out.println(ans);
    } 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];
        int x = 1;
        int ans = 0;

        for(int i=0; i<N; i++){
            K[i] = sc.nextInt();
            for(int j=0; j<K[i]; j++){
                A[i][j] = sc.nextInt();
            }
        }
        if(N>1){
            for(int i=0; i<M; i++){
                loop:for(int j=1; j<N; j++){
                    for(int k=0; k<K[j]; k++){
                        if(A[0][i]==A[j][k]){
                            x += 1;
                            break;
                        }
                        else if(A[0][i]!=A[j][M-1] && k==M-1){
                            x = 0;
                            break loop;
                        }
                    }
                }
                if(x==N){
                    ans += 1;
                }
                x = 1;
            }
        }
        if(N==1){
            ans = K[0];
        }
        System.out.println(ans);
    } 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 int x = 1; x 1 int ans = 0; ans 0 for(int i=0; i<N; i++){
            K[i] = sc.nextInt();
            for(int j=0; j<K[i]; j++){
                A[i][j] = sc.nextInt();
            }
        } 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++){
                A[i][j] = sc.nextInt();
            }
        } {
            K[i] = sc.nextInt();
            for(int j=0; j<K[i]; j++){
                A[i][j] = sc.nextInt();
            }
        } K[i] = sc.nextInt() K[i] K i sc.nextInt() sc.nextInt sc for(int j=0; j<K[i]; j++){
                A[i][j] = sc.nextInt();
            } int j=0; int j=0; j 0 j<K[i] j K[i] K i j++ j++ j {
                A[i][j] = sc.nextInt();
            } {
                A[i][j] = sc.nextInt();
            } A[i][j] = sc.nextInt() A[i][j] A[i] A i j sc.nextInt() sc.nextInt sc if(N>1){
            for(int i=0; i<M; i++){
                loop:for(int j=1; j<N; j++){
                    for(int k=0; k<K[j]; k++){
                        if(A[0][i]==A[j][k]){
                            x += 1;
                            break;
                        }
                        else if(A[0][i]!=A[j][M-1] && k==M-1){
                            x = 0;
                            break loop;
                        }
                    }
                }
                if(x==N){
                    ans += 1;
                }
                x = 1;
            }
        } N>1 N 1 {
            for(int i=0; i<M; i++){
                loop:for(int j=1; j<N; j++){
                    for(int k=0; k<K[j]; k++){
                        if(A[0][i]==A[j][k]){
                            x += 1;
                            break;
                        }
                        else if(A[0][i]!=A[j][M-1] && k==M-1){
                            x = 0;
                            break loop;
                        }
                    }
                }
                if(x==N){
                    ans += 1;
                }
                x = 1;
            }
        } for(int i=0; i<M; i++){
                loop:for(int j=1; j<N; j++){
                    for(int k=0; k<K[j]; k++){
                        if(A[0][i]==A[j][k]){
                            x += 1;
                            break;
                        }
                        else if(A[0][i]!=A[j][M-1] && k==M-1){
                            x = 0;
                            break loop;
                        }
                    }
                }
                if(x==N){
                    ans += 1;
                }
                x = 1;
            } int i=0; int i=0; i 0 i<M i M i++ i++ i {
                loop:for(int j=1; j<N; j++){
                    for(int k=0; k<K[j]; k++){
                        if(A[0][i]==A[j][k]){
                            x += 1;
                            break;
                        }
                        else if(A[0][i]!=A[j][M-1] && k==M-1){
                            x = 0;
                            break loop;
                        }
                    }
                }
                if(x==N){
                    ans += 1;
                }
                x = 1;
            } {
                loop:for(int j=1; j<N; j++){
                    for(int k=0; k<K[j]; k++){
                        if(A[0][i]==A[j][k]){
                            x += 1;
                            break;
                        }
                        else if(A[0][i]!=A[j][M-1] && k==M-1){
                            x = 0;
                            break loop;
                        }
                    }
                }
                if(x==N){
                    ans += 1;
                }
                x = 1;
            } if(x==N){
                    ans += 1;
                } x==N x N {
                    ans += 1;
                } ans += 1 ans 1 x = 1 x 1 if(N==1){
            ans = K[0];
        } N==1 N 1 {
            ans = K[0];
        } ans = K[0] ans K[0] K 0 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 sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] K = new int[N];
        int[][] A = new int[N][M];
        int x = 1;
        int ans = 0;

        for(int i=0; i<N; i++){
            K[i] = sc.nextInt();
            for(int j=0; j<K[i]; j++){
                A[i][j] = sc.nextInt();
            }
        }
        if(N>1){
            for(int i=0; i<M; i++){
                loop:for(int j=1; j<N; j++){
                    for(int k=0; k<K[j]; k++){
                        if(A[0][i]==A[j][k]){
                            x += 1;
                            break;
                        }
                        else if(A[0][i]!=A[j][M-1] && k==M-1){
                            x = 0;
                            break loop;
                        }
                    }
                }
                if(x==N){
                    ans += 1;
                }
                x = 1;
            }
        }
        if(N==1){
            ans = K[0];
        }
        System.out.println(ans);
    }
} 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];
        int x = 1;
        int ans = 0;

        for(int i=0; i<N; i++){
            K[i] = sc.nextInt();
            for(int j=0; j<K[i]; j++){
                A[i][j] = sc.nextInt();
            }
        }
        if(N>1){
            for(int i=0; i<M; i++){
                loop:for(int j=1; j<N; j++){
                    for(int k=0; k<K[j]; k++){
                        if(A[0][i]==A[j][k]){
                            x += 1;
                            break;
                        }
                        else if(A[0][i]!=A[j][M-1] && k==M-1){
                            x = 0;
                            break loop;
                        }
                    }
                }
                if(x==N){
                    ans += 1;
                }
                x = 1;
            }
        }
        if(N==1){
            ans = K[0];
        }
        System.out.println(ans);
    }
} 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];
        int x = 1;
        int ans = 0;

        for(int i=0; i<N; i++){
            K[i] = sc.nextInt();
            for(int j=0; j<K[i]; j++){
                A[i][j] = sc.nextInt();
            }
        }
        if(N>1){
            for(int i=0; i<M; i++){
                loop:for(int j=1; j<N; j++){
                    for(int k=0; k<K[j]; k++){
                        if(A[0][i]==A[j][k]){
                            x += 1;
                            break;
                        }
                        else if(A[0][i]!=A[j][M-1] && k==M-1){
                            x = 0;
                            break loop;
                        }
                    }
                }
                if(x==N){
                    ans += 1;
                }
                x = 1;
            }
        }
        if(N==1){
            ans = K[0];
        }
        System.out.println(ans);
    }
}