

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        ArrayList<Integer>[] list = new ArrayList[N];
        for (int i=0; i<N; i++) {
            list[i] = new ArrayList<Integer>();
        }
        for (int i=0; i<N; i++) {
            int S = sc.nextInt();
            for (int j=0; j<S; j++) {
                list[i].add(sc.nextInt());
            }
        }
        int counter = 0;
        for (int i=0; i<=M; i++) {
            boolean flag = true;
            for (int j=0; j<N; j++) {
                if (list[j].contains(i)) {
                } else {
                    flag = false;
                }
            }
            if (flag) {
                counter++;
            }
        }
        System.out.println(counter);
    }
} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner 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();
        ArrayList<Integer>[] list = new ArrayList[N];
        for (int i=0; i<N; i++) {
            list[i] = new ArrayList<Integer>();
        }
        for (int i=0; i<N; i++) {
            int S = sc.nextInt();
            for (int j=0; j<S; j++) {
                list[i].add(sc.nextInt());
            }
        }
        int counter = 0;
        for (int i=0; i<=M; i++) {
            boolean flag = true;
            for (int j=0; j<N; j++) {
                if (list[j].contains(i)) {
                } else {
                    flag = false;
                }
            }
            if (flag) {
                counter++;
            }
        }
        System.out.println(counter);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        ArrayList<Integer>[] list = new ArrayList[N];
        for (int i=0; i<N; i++) {
            list[i] = new ArrayList<Integer>();
        }
        for (int i=0; i<N; i++) {
            int S = sc.nextInt();
            for (int j=0; j<S; j++) {
                list[i].add(sc.nextInt());
            }
        }
        int counter = 0;
        for (int i=0; i<=M; i++) {
            boolean flag = true;
            for (int j=0; j<N; j++) {
                if (list[j].contains(i)) {
                } else {
                    flag = false;
                }
            }
            if (flag) {
                counter++;
            }
        }
        System.out.println(counter);
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        ArrayList<Integer>[] list = new ArrayList[N];
        for (int i=0; i<N; i++) {
            list[i] = new ArrayList<Integer>();
        }
        for (int i=0; i<N; i++) {
            int S = sc.nextInt();
            for (int j=0; j<S; j++) {
                list[i].add(sc.nextInt());
            }
        }
        int counter = 0;
        for (int i=0; i<=M; i++) {
            boolean flag = true;
            for (int j=0; j<N; j++) {
                if (list[j].contains(i)) {
                } else {
                    flag = false;
                }
            }
            if (flag) {
                counter++;
            }
        }
        System.out.println(counter);
    } 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 ArrayList<Integer>[] list = new ArrayList[N]; list new ArrayList[N] N for (int i=0; i<N; i++) {
            list[i] = new ArrayList<Integer>();
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            list[i] = new ArrayList<Integer>();
        } {
            list[i] = new ArrayList<Integer>();
        } list[i] = new ArrayList<Integer>() list[i] list i new ArrayList<Integer>() for (int i=0; i<N; i++) {
            int S = sc.nextInt();
            for (int j=0; j<S; j++) {
                list[i].add(sc.nextInt());
            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            int S = sc.nextInt();
            for (int j=0; j<S; j++) {
                list[i].add(sc.nextInt());
            }
        } {
            int S = sc.nextInt();
            for (int j=0; j<S; j++) {
                list[i].add(sc.nextInt());
            }
        } int S = sc.nextInt(); S sc.nextInt() sc.nextInt sc for (int j=0; j<S; j++) {
                list[i].add(sc.nextInt());
            } int j=0; int j=0; j 0 j<S j S j++ j++ j {
                list[i].add(sc.nextInt());
            } {
                list[i].add(sc.nextInt());
            } list[i].add(sc.nextInt()) list[i].add list[i] list i sc.nextInt() sc.nextInt sc int counter = 0; counter 0 for (int i=0; i<=M; i++) {
            boolean flag = true;
            for (int j=0; j<N; j++) {
                if (list[j].contains(i)) {
                } else {
                    flag = false;
                }
            }
            if (flag) {
                counter++;
            }
        } int i=0; int i=0; i 0 i<=M i M i++ i++ i {
            boolean flag = true;
            for (int j=0; j<N; j++) {
                if (list[j].contains(i)) {
                } else {
                    flag = false;
                }
            }
            if (flag) {
                counter++;
            }
        } {
            boolean flag = true;
            for (int j=0; j<N; j++) {
                if (list[j].contains(i)) {
                } else {
                    flag = false;
                }
            }
            if (flag) {
                counter++;
            }
        } boolean flag = true; flag true for (int j=0; j<N; j++) {
                if (list[j].contains(i)) {
                } else {
                    flag = false;
                }
            } int j=0; int j=0; j 0 j<N j N j++ j++ j {
                if (list[j].contains(i)) {
                } else {
                    flag = false;
                }
            } {
                if (list[j].contains(i)) {
                } else {
                    flag = false;
                }
            } if (list[j].contains(i)) {
                } else {
                    flag = false;
                } list[j].contains(i) list[j].contains list[j] list j i {
                } {
                    flag = false;
                } flag = false flag false if (flag) {
                counter++;
            } flag {
                counter++;
            } counter++ counter System.out.println(counter) System.out.println System.out System System.out counter 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();
        ArrayList<Integer>[] list = new ArrayList[N];
        for (int i=0; i<N; i++) {
            list[i] = new ArrayList<Integer>();
        }
        for (int i=0; i<N; i++) {
            int S = sc.nextInt();
            for (int j=0; j<S; j++) {
                list[i].add(sc.nextInt());
            }
        }
        int counter = 0;
        for (int i=0; i<=M; i++) {
            boolean flag = true;
            for (int j=0; j<N; j++) {
                if (list[j].contains(i)) {
                } else {
                    flag = false;
                }
            }
            if (flag) {
                counter++;
            }
        }
        System.out.println(counter);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        ArrayList<Integer>[] list = new ArrayList[N];
        for (int i=0; i<N; i++) {
            list[i] = new ArrayList<Integer>();
        }
        for (int i=0; i<N; i++) {
            int S = sc.nextInt();
            for (int j=0; j<S; j++) {
                list[i].add(sc.nextInt());
            }
        }
        int counter = 0;
        for (int i=0; i<=M; i++) {
            boolean flag = true;
            for (int j=0; j<N; j++) {
                if (list[j].contains(i)) {
                } else {
                    flag = false;
                }
            }
            if (flag) {
                counter++;
            }
        }
        System.out.println(counter);
    }
} Main


import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        ArrayList<Integer>[] list = new ArrayList[N];
        for (int i=0; i<N; i++) {
            list[i] = new ArrayList<Integer>();
        }
        for (int i=0; i<N; i++) {
            int S = sc.nextInt();
            for (int j=0; j<S; j++) {
                list[i].add(sc.nextInt());
            }
        }
        int counter = 0;
        for (int i=0; i<=M; i++) {
            boolean flag = true;
            for (int j=0; j<N; j++) {
                if (list[j].contains(i)) {
                } else {
                    flag = false;
                }
            }
            if (flag) {
                counter++;
            }
        }
        System.out.println(counter);
    }
}
