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