import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        q_2();
    }

    private static void q_1() {
        try (Scanner scan = new Scanner(System.in)) {
            int a = scan.nextInt();
            int b = scan.nextInt();

            System.out.println(b % a == 0 ? b + a : b - a);
        }
    }

    private static void q_2() {
        try (Scanner scan = new Scanner(System.in)) {
            int n = scan.nextInt(); // n人
            int m = scan.nextInt(); // m種類

            Map<Integer, Integer> a = new HashMap<>();
            for(int i=0; i<n; i++) {
                int k = scan.nextInt();
                for(int j=0; j<k; j++) {
                    int am = scan.nextInt();
                    if(a.get(am) == null) {
                        a.put(am, 1);
                    } else {
                        a.put(am, a.get(am) + 1);
                    }
                }
            }

            int cnt = 0;

            for (Integer val : a.values()) {
                if(val == n) {
                    cnt ++;
                }
            }

            System.out.println(cnt);

        }
    }
} import java.util.HashMap; HashMap java.util import java.util.Map; Map java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        q_2();
    }

    private static void q_1() {
        try (Scanner scan = new Scanner(System.in)) {
            int a = scan.nextInt();
            int b = scan.nextInt();

            System.out.println(b % a == 0 ? b + a : b - a);
        }
    }

    private static void q_2() {
        try (Scanner scan = new Scanner(System.in)) {
            int n = scan.nextInt(); // n人
            int m = scan.nextInt(); // m種類

            Map<Integer, Integer> a = new HashMap<>();
            for(int i=0; i<n; i++) {
                int k = scan.nextInt();
                for(int j=0; j<k; j++) {
                    int am = scan.nextInt();
                    if(a.get(am) == null) {
                        a.put(am, 1);
                    } else {
                        a.put(am, a.get(am) + 1);
                    }
                }
            }

            int cnt = 0;

            for (Integer val : a.values()) {
                if(val == n) {
                    cnt ++;
                }
            }

            System.out.println(cnt);

        }
    }
} Main public static void main(String[] args) {
        q_2();
    } main {
        q_2();
    } q_2() q_2 String[] args args private static void q_1() {
        try (Scanner scan = new Scanner(System.in)) {
            int a = scan.nextInt();
            int b = scan.nextInt();

            System.out.println(b % a == 0 ? b + a : b - a);
        }
    } q_1 {
        try (Scanner scan = new Scanner(System.in)) {
            int a = scan.nextInt();
            int b = scan.nextInt();

            System.out.println(b % a == 0 ? b + a : b - a);
        }
    } try (Scanner scan = new Scanner(System.in)) {
            int a = scan.nextInt();
            int b = scan.nextInt();

            System.out.println(b % a == 0 ? b + a : b - a);
        } {
            int a = scan.nextInt();
            int b = scan.nextInt();

            System.out.println(b % a == 0 ? b + a : b - a);
        } Scanner scan = new Scanner(System.in) Scanner scan = new Scanner(System.in) new Scanner(System.in) int a = scan.nextInt(); a scan.nextInt() scan.nextInt scan int b = scan.nextInt(); b scan.nextInt() scan.nextInt scan System.out.println(b % a == 0 ? b + a : b - a) System.out.println System.out System System.out b % a == 0 ? b + a : b - a b % a == 0 b % a b a 0 b + a b a b - a b a private static void q_2() {
        try (Scanner scan = new Scanner(System.in)) {
            int n = scan.nextInt(); // n人
            int m = scan.nextInt(); // m種類

            Map<Integer, Integer> a = new HashMap<>();
            for(int i=0; i<n; i++) {
                int k = scan.nextInt();
                for(int j=0; j<k; j++) {
                    int am = scan.nextInt();
                    if(a.get(am) == null) {
                        a.put(am, 1);
                    } else {
                        a.put(am, a.get(am) + 1);
                    }
                }
            }

            int cnt = 0;

            for (Integer val : a.values()) {
                if(val == n) {
                    cnt ++;
                }
            }

            System.out.println(cnt);

        }
    } q_2 {
        try (Scanner scan = new Scanner(System.in)) {
            int n = scan.nextInt(); // n人
            int m = scan.nextInt(); // m種類

            Map<Integer, Integer> a = new HashMap<>();
            for(int i=0; i<n; i++) {
                int k = scan.nextInt();
                for(int j=0; j<k; j++) {
                    int am = scan.nextInt();
                    if(a.get(am) == null) {
                        a.put(am, 1);
                    } else {
                        a.put(am, a.get(am) + 1);
                    }
                }
            }

            int cnt = 0;

            for (Integer val : a.values()) {
                if(val == n) {
                    cnt ++;
                }
            }

            System.out.println(cnt);

        }
    } try (Scanner scan = new Scanner(System.in)) {
            int n = scan.nextInt(); // n人
            int m = scan.nextInt(); // m種類

            Map<Integer, Integer> a = new HashMap<>();
            for(int i=0; i<n; i++) {
                int k = scan.nextInt();
                for(int j=0; j<k; j++) {
                    int am = scan.nextInt();
                    if(a.get(am) == null) {
                        a.put(am, 1);
                    } else {
                        a.put(am, a.get(am) + 1);
                    }
                }
            }

            int cnt = 0;

            for (Integer val : a.values()) {
                if(val == n) {
                    cnt ++;
                }
            }

            System.out.println(cnt);

        } {
            int n = scan.nextInt(); // n人
            int m = scan.nextInt(); // m種類

            Map<Integer, Integer> a = new HashMap<>();
            for(int i=0; i<n; i++) {
                int k = scan.nextInt();
                for(int j=0; j<k; j++) {
                    int am = scan.nextInt();
                    if(a.get(am) == null) {
                        a.put(am, 1);
                    } else {
                        a.put(am, a.get(am) + 1);
                    }
                }
            }

            int cnt = 0;

            for (Integer val : a.values()) {
                if(val == n) {
                    cnt ++;
                }
            }

            System.out.println(cnt);

        } Scanner scan = new Scanner(System.in) Scanner scan = new Scanner(System.in) new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int m = scan.nextInt(); m scan.nextInt() scan.nextInt scan Map<Integer, Integer> a = new HashMap<>(); a new HashMap<>() for(int i=0; i<n; i++) {
                int k = scan.nextInt();
                for(int j=0; j<k; j++) {
                    int am = scan.nextInt();
                    if(a.get(am) == null) {
                        a.put(am, 1);
                    } else {
                        a.put(am, a.get(am) + 1);
                    }
                }
            } int i=0; int i=0; i 0 i<n i n i++ i++ i {
                int k = scan.nextInt();
                for(int j=0; j<k; j++) {
                    int am = scan.nextInt();
                    if(a.get(am) == null) {
                        a.put(am, 1);
                    } else {
                        a.put(am, a.get(am) + 1);
                    }
                }
            } {
                int k = scan.nextInt();
                for(int j=0; j<k; j++) {
                    int am = scan.nextInt();
                    if(a.get(am) == null) {
                        a.put(am, 1);
                    } else {
                        a.put(am, a.get(am) + 1);
                    }
                }
            } int k = scan.nextInt(); k scan.nextInt() scan.nextInt scan for(int j=0; j<k; j++) {
                    int am = scan.nextInt();
                    if(a.get(am) == null) {
                        a.put(am, 1);
                    } else {
                        a.put(am, a.get(am) + 1);
                    }
                } int j=0; int j=0; j 0 j<k j k j++ j++ j {
                    int am = scan.nextInt();
                    if(a.get(am) == null) {
                        a.put(am, 1);
                    } else {
                        a.put(am, a.get(am) + 1);
                    }
                } {
                    int am = scan.nextInt();
                    if(a.get(am) == null) {
                        a.put(am, 1);
                    } else {
                        a.put(am, a.get(am) + 1);
                    }
                } int am = scan.nextInt(); am scan.nextInt() scan.nextInt scan if(a.get(am) == null) {
                        a.put(am, 1);
                    } else {
                        a.put(am, a.get(am) + 1);
                    } a.get(am) == null a.get(am) a.get a am null {
                        a.put(am, 1);
                    } a.put(am, 1) a.put a am 1 {
                        a.put(am, a.get(am) + 1);
                    } a.put(am, a.get(am) + 1) a.put a am a.get(am) + 1 a.get(am) a.get a am 1 int cnt = 0; cnt 0 for (Integer val : a.values()) {
                if(val == n) {
                    cnt ++;
                }
            } Integer val a.values() a.values a {
                if(val == n) {
                    cnt ++;
                }
            } {
                if(val == n) {
                    cnt ++;
                }
            } if(val == n) {
                    cnt ++;
                } val == n val n {
                    cnt ++;
                } cnt ++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt public class Main {
    public static void main(String[] args) {
        q_2();
    }

    private static void q_1() {
        try (Scanner scan = new Scanner(System.in)) {
            int a = scan.nextInt();
            int b = scan.nextInt();

            System.out.println(b % a == 0 ? b + a : b - a);
        }
    }

    private static void q_2() {
        try (Scanner scan = new Scanner(System.in)) {
            int n = scan.nextInt(); // n人
            int m = scan.nextInt(); // m種類

            Map<Integer, Integer> a = new HashMap<>();
            for(int i=0; i<n; i++) {
                int k = scan.nextInt();
                for(int j=0; j<k; j++) {
                    int am = scan.nextInt();
                    if(a.get(am) == null) {
                        a.put(am, 1);
                    } else {
                        a.put(am, a.get(am) + 1);
                    }
                }
            }

            int cnt = 0;

            for (Integer val : a.values()) {
                if(val == n) {
                    cnt ++;
                }
            }

            System.out.println(cnt);

        }
    }
} public class Main {
    public static void main(String[] args) {
        q_2();
    }

    private static void q_1() {
        try (Scanner scan = new Scanner(System.in)) {
            int a = scan.nextInt();
            int b = scan.nextInt();

            System.out.println(b % a == 0 ? b + a : b - a);
        }
    }

    private static void q_2() {
        try (Scanner scan = new Scanner(System.in)) {
            int n = scan.nextInt(); // n人
            int m = scan.nextInt(); // m種類

            Map<Integer, Integer> a = new HashMap<>();
            for(int i=0; i<n; i++) {
                int k = scan.nextInt();
                for(int j=0; j<k; j++) {
                    int am = scan.nextInt();
                    if(a.get(am) == null) {
                        a.put(am, 1);
                    } else {
                        a.put(am, a.get(am) + 1);
                    }
                }
            }

            int cnt = 0;

            for (Integer val : a.values()) {
                if(val == n) {
                    cnt ++;
                }
            }

            System.out.println(cnt);

        }
    }
} Main
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        q_2();
    }

    private static void q_1() {
        try (Scanner scan = new Scanner(System.in)) {
            int a = scan.nextInt();
            int b = scan.nextInt();

            System.out.println(b % a == 0 ? b + a : b - a);
        }
    }

    private static void q_2() {
        try (Scanner scan = new Scanner(System.in)) {
            int n = scan.nextInt(); // n人
            int m = scan.nextInt(); // m種類

            Map<Integer, Integer> a = new HashMap<>();
            for(int i=0; i<n; i++) {
                int k = scan.nextInt();
                for(int j=0; j<k; j++) {
                    int am = scan.nextInt();
                    if(a.get(am) == null) {
                        a.put(am, 1);
                    } else {
                        a.put(am, a.get(am) + 1);
                    }
                }
            }

            int cnt = 0;

            for (Integer val : a.values()) {
                if(val == n) {
                    cnt ++;
                }
            }

            System.out.println(cnt);

        }
    }
}
