import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] nm = scanner.nextLine().split(" ", 2);
        int n = Integer.parseInt(nm[0]);
        int m = Integer.parseInt(nm[1]);

        boolean[] like = new boolean[m+1];
        Arrays.fill(like, true);

        for (int i = 0; i < n; i++) {
            String[] line = scanner.nextLine().split(" ", -1);
            int k = Integer.parseInt(line[0]);

            boolean[] lineLike = new boolean[m+1];
            for (int j = 1; j <= k; j++) {
                int a = Integer.parseInt(line[j]);
                lineLike[a] = true;
            }
            for (int j = 1; j <= m; j++) {
                if (!lineLike[j]) {
                    like[j] = false;
                }
            }
        }

        int num = 0;
        for (int i = 1; i <= m; i++) {
            if (like[i]) {
                num++;
            }
        }
        System.out.println(num);
    }
} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] nm = scanner.nextLine().split(" ", 2);
        int n = Integer.parseInt(nm[0]);
        int m = Integer.parseInt(nm[1]);

        boolean[] like = new boolean[m+1];
        Arrays.fill(like, true);

        for (int i = 0; i < n; i++) {
            String[] line = scanner.nextLine().split(" ", -1);
            int k = Integer.parseInt(line[0]);

            boolean[] lineLike = new boolean[m+1];
            for (int j = 1; j <= k; j++) {
                int a = Integer.parseInt(line[j]);
                lineLike[a] = true;
            }
            for (int j = 1; j <= m; j++) {
                if (!lineLike[j]) {
                    like[j] = false;
                }
            }
        }

        int num = 0;
        for (int i = 1; i <= m; i++) {
            if (like[i]) {
                num++;
            }
        }
        System.out.println(num);
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] nm = scanner.nextLine().split(" ", 2);
        int n = Integer.parseInt(nm[0]);
        int m = Integer.parseInt(nm[1]);

        boolean[] like = new boolean[m+1];
        Arrays.fill(like, true);

        for (int i = 0; i < n; i++) {
            String[] line = scanner.nextLine().split(" ", -1);
            int k = Integer.parseInt(line[0]);

            boolean[] lineLike = new boolean[m+1];
            for (int j = 1; j <= k; j++) {
                int a = Integer.parseInt(line[j]);
                lineLike[a] = true;
            }
            for (int j = 1; j <= m; j++) {
                if (!lineLike[j]) {
                    like[j] = false;
                }
            }
        }

        int num = 0;
        for (int i = 1; i <= m; i++) {
            if (like[i]) {
                num++;
            }
        }
        System.out.println(num);
    } main {
        Scanner scanner = new Scanner(System.in);
        String[] nm = scanner.nextLine().split(" ", 2);
        int n = Integer.parseInt(nm[0]);
        int m = Integer.parseInt(nm[1]);

        boolean[] like = new boolean[m+1];
        Arrays.fill(like, true);

        for (int i = 0; i < n; i++) {
            String[] line = scanner.nextLine().split(" ", -1);
            int k = Integer.parseInt(line[0]);

            boolean[] lineLike = new boolean[m+1];
            for (int j = 1; j <= k; j++) {
                int a = Integer.parseInt(line[j]);
                lineLike[a] = true;
            }
            for (int j = 1; j <= m; j++) {
                if (!lineLike[j]) {
                    like[j] = false;
                }
            }
        }

        int num = 0;
        for (int i = 1; i <= m; i++) {
            if (like[i]) {
                num++;
            }
        }
        System.out.println(num);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String[] nm = scanner.nextLine().split(" ", 2); nm scanner.nextLine().split(" ", 2) scanner.nextLine().split scanner.nextLine() scanner.nextLine scanner " " 2 int n = Integer.parseInt(nm[0]); n Integer.parseInt(nm[0]) Integer.parseInt Integer nm[0] nm 0 int m = Integer.parseInt(nm[1]); m Integer.parseInt(nm[1]) Integer.parseInt Integer nm[1] nm 1 boolean[] like = new boolean[m+1]; like new boolean[m+1] m+1 m 1 Arrays.fill(like, true) Arrays.fill Arrays like true for (int i = 0; i < n; i++) {
            String[] line = scanner.nextLine().split(" ", -1);
            int k = Integer.parseInt(line[0]);

            boolean[] lineLike = new boolean[m+1];
            for (int j = 1; j <= k; j++) {
                int a = Integer.parseInt(line[j]);
                lineLike[a] = true;
            }
            for (int j = 1; j <= m; j++) {
                if (!lineLike[j]) {
                    like[j] = false;
                }
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            String[] line = scanner.nextLine().split(" ", -1);
            int k = Integer.parseInt(line[0]);

            boolean[] lineLike = new boolean[m+1];
            for (int j = 1; j <= k; j++) {
                int a = Integer.parseInt(line[j]);
                lineLike[a] = true;
            }
            for (int j = 1; j <= m; j++) {
                if (!lineLike[j]) {
                    like[j] = false;
                }
            }
        } {
            String[] line = scanner.nextLine().split(" ", -1);
            int k = Integer.parseInt(line[0]);

            boolean[] lineLike = new boolean[m+1];
            for (int j = 1; j <= k; j++) {
                int a = Integer.parseInt(line[j]);
                lineLike[a] = true;
            }
            for (int j = 1; j <= m; j++) {
                if (!lineLike[j]) {
                    like[j] = false;
                }
            }
        } String[] line = scanner.nextLine().split(" ", -1); line scanner.nextLine().split(" ", -1) scanner.nextLine().split scanner.nextLine() scanner.nextLine scanner " " -1 1 int k = Integer.parseInt(line[0]); k Integer.parseInt(line[0]) Integer.parseInt Integer line[0] line 0 boolean[] lineLike = new boolean[m+1]; lineLike new boolean[m+1] m+1 m 1 for (int j = 1; j <= k; j++) {
                int a = Integer.parseInt(line[j]);
                lineLike[a] = true;
            } int j = 1; int j = 1; j 1 j <= k j k j++ j++ j {
                int a = Integer.parseInt(line[j]);
                lineLike[a] = true;
            } {
                int a = Integer.parseInt(line[j]);
                lineLike[a] = true;
            } int a = Integer.parseInt(line[j]); a Integer.parseInt(line[j]) Integer.parseInt Integer line[j] line j lineLike[a] = true lineLike[a] lineLike a true for (int j = 1; j <= m; j++) {
                if (!lineLike[j]) {
                    like[j] = false;
                }
            } int j = 1; int j = 1; j 1 j <= m j m j++ j++ j {
                if (!lineLike[j]) {
                    like[j] = false;
                }
            } {
                if (!lineLike[j]) {
                    like[j] = false;
                }
            } if (!lineLike[j]) {
                    like[j] = false;
                } !lineLike[j] lineLike[j] lineLike j {
                    like[j] = false;
                } like[j] = false like[j] like j false int num = 0; num 0 for (int i = 1; i <= m; i++) {
            if (like[i]) {
                num++;
            }
        } int i = 1; int i = 1; i 1 i <= m i m i++ i++ i {
            if (like[i]) {
                num++;
            }
        } {
            if (like[i]) {
                num++;
            }
        } if (like[i]) {
                num++;
            } like[i] like i {
                num++;
            } num++ num System.out.println(num) System.out.println System.out System System.out num String[] args args
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] nm = scanner.nextLine().split(" ", 2);
        int n = Integer.parseInt(nm[0]);
        int m = Integer.parseInt(nm[1]);

        boolean[] like = new boolean[m+1];
        Arrays.fill(like, true);

        for (int i = 0; i < n; i++) {
            String[] line = scanner.nextLine().split(" ", -1);
            int k = Integer.parseInt(line[0]);

            boolean[] lineLike = new boolean[m+1];
            for (int j = 1; j <= k; j++) {
                int a = Integer.parseInt(line[j]);
                lineLike[a] = true;
            }
            for (int j = 1; j <= m; j++) {
                if (!lineLike[j]) {
                    like[j] = false;
                }
            }
        }

        int num = 0;
        for (int i = 1; i <= m; i++) {
            if (like[i]) {
                num++;
            }
        }
        System.out.println(num);
    }
}
