import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();

        BitSet master = new BitSet(m);
        master.set(1, m + 1);
        for (int i = 0; i < n; ++i) {
            int k = scan.nextInt();

            BitSet bitset = new BitSet(m);
            for (int j = 0; j < k; ++j) {
                bitset.set(scan.nextInt());
            }
            master.and(bitset);
        }
        System.out.println(master.cardinality());
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();

        BitSet master = new BitSet(m);
        master.set(1, m + 1);
        for (int i = 0; i < n; ++i) {
            int k = scan.nextInt();

            BitSet bitset = new BitSet(m);
            for (int j = 0; j < k; ++j) {
                bitset.set(scan.nextInt());
            }
            master.and(bitset);
        }
        System.out.println(master.cardinality());
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();

        BitSet master = new BitSet(m);
        master.set(1, m + 1);
        for (int i = 0; i < n; ++i) {
            int k = scan.nextInt();

            BitSet bitset = new BitSet(m);
            for (int j = 0; j < k; ++j) {
                bitset.set(scan.nextInt());
            }
            master.and(bitset);
        }
        System.out.println(master.cardinality());
    } main {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();

        BitSet master = new BitSet(m);
        master.set(1, m + 1);
        for (int i = 0; i < n; ++i) {
            int k = scan.nextInt();

            BitSet bitset = new BitSet(m);
            for (int j = 0; j < k; ++j) {
                bitset.set(scan.nextInt());
            }
            master.and(bitset);
        }
        System.out.println(master.cardinality());
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int m = scan.nextInt(); m scan.nextInt() scan.nextInt scan BitSet master = new BitSet(m); master new BitSet(m) master.set(1, m + 1) master.set master 1 m + 1 m 1 for (int i = 0; i < n; ++i) {
            int k = scan.nextInt();

            BitSet bitset = new BitSet(m);
            for (int j = 0; j < k; ++j) {
                bitset.set(scan.nextInt());
            }
            master.and(bitset);
        } int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
            int k = scan.nextInt();

            BitSet bitset = new BitSet(m);
            for (int j = 0; j < k; ++j) {
                bitset.set(scan.nextInt());
            }
            master.and(bitset);
        } {
            int k = scan.nextInt();

            BitSet bitset = new BitSet(m);
            for (int j = 0; j < k; ++j) {
                bitset.set(scan.nextInt());
            }
            master.and(bitset);
        } int k = scan.nextInt(); k scan.nextInt() scan.nextInt scan BitSet bitset = new BitSet(m); bitset new BitSet(m) for (int j = 0; j < k; ++j) {
                bitset.set(scan.nextInt());
            } int j = 0; int j = 0; j 0 j < k j k ++j ++j j {
                bitset.set(scan.nextInt());
            } {
                bitset.set(scan.nextInt());
            } bitset.set(scan.nextInt()) bitset.set bitset scan.nextInt() scan.nextInt scan master.and(bitset) master.and master bitset System.out.println(master.cardinality()) System.out.println System.out System System.out master.cardinality() master.cardinality master String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();

        BitSet master = new BitSet(m);
        master.set(1, m + 1);
        for (int i = 0; i < n; ++i) {
            int k = scan.nextInt();

            BitSet bitset = new BitSet(m);
            for (int j = 0; j < k; ++j) {
                bitset.set(scan.nextInt());
            }
            master.and(bitset);
        }
        System.out.println(master.cardinality());
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();

        BitSet master = new BitSet(m);
        master.set(1, m + 1);
        for (int i = 0; i < n; ++i) {
            int k = scan.nextInt();

            BitSet bitset = new BitSet(m);
            for (int j = 0; j < k; ++j) {
                bitset.set(scan.nextInt());
            }
            master.and(bitset);
        }
        System.out.println(master.cardinality());
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();

        BitSet master = new BitSet(m);
        master.set(1, m + 1);
        for (int i = 0; i < n; ++i) {
            int k = scan.nextInt();

            BitSet bitset = new BitSet(m);
            for (int j = 0; j < k; ++j) {
                bitset.set(scan.nextInt());
            }
            master.and(bitset);
        }
        System.out.println(master.cardinality());
    }
}