import 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();
      int[][] a = new int[n][m];
      for (int i = 0; i < n; i++) {
        int k = sc.nextInt();
        for (int j = 0; j < k; j++) {
          a[i][j] = sc.nextInt();
        }
      }
      int[] list = new int[m+1];
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (a[i][j] > 0) {
            list[a[i][j]] += 1;
          }
        }
      }
      int ans = 0;
      for (int i = 0; i < m+1; i++) {
        if (list[i] == n) {
          ans++;
        }
      }
      System.out.println(ans);
    }
  } import java.util.*; util.* java public 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];
      for (int i = 0; i < n; i++) {
        int k = sc.nextInt();
        for (int j = 0; j < k; j++) {
          a[i][j] = sc.nextInt();
        }
      }
      int[] list = new int[m+1];
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (a[i][j] > 0) {
            list[a[i][j]] += 1;
          }
        }
      }
      int ans = 0;
      for (int i = 0; i < m+1; i++) {
        if (list[i] == n) {
          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];
      for (int i = 0; i < n; i++) {
        int k = sc.nextInt();
        for (int j = 0; j < k; j++) {
          a[i][j] = sc.nextInt();
        }
      }
      int[] list = new int[m+1];
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (a[i][j] > 0) {
            list[a[i][j]] += 1;
          }
        }
      }
      int ans = 0;
      for (int i = 0; i < m+1; i++) {
        if (list[i] == n) {
          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];
      for (int i = 0; i < n; i++) {
        int k = sc.nextInt();
        for (int j = 0; j < k; j++) {
          a[i][j] = sc.nextInt();
        }
      }
      int[] list = new int[m+1];
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (a[i][j] > 0) {
            list[a[i][j]] += 1;
          }
        }
      }
      int ans = 0;
      for (int i = 0; i < m+1; i++) {
        if (list[i] == n) {
          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 for (int i = 0; i < n; i++) {
        int k = sc.nextInt();
        for (int j = 0; j < k; j++) {
          a[i][j] = sc.nextInt();
        }
      } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        int k = sc.nextInt();
        for (int j = 0; j < k; j++) {
          a[i][j] = sc.nextInt();
        }
      } {
        int k = sc.nextInt();
        for (int j = 0; j < k; j++) {
          a[i][j] = sc.nextInt();
        }
      } int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc for (int j = 0; j < k; j++) {
          a[i][j] = sc.nextInt();
        } int j = 0; int j = 0; j 0 j < k j k j++ j++ j {
          a[i][j] = sc.nextInt();
        } {
          a[i][j] = sc.nextInt();
        } a[i][j] = sc.nextInt() a[i][j] a[i] a i j sc.nextInt() sc.nextInt sc int[] list = new int[m+1]; list new int[m+1] m+1 m 1 for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (a[i][j] > 0) {
            list[a[i][j]] += 1;
          }
        }
      } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        for (int j = 0; j < m; j++) {
          if (a[i][j] > 0) {
            list[a[i][j]] += 1;
          }
        }
      } {
        for (int j = 0; j < m; j++) {
          if (a[i][j] > 0) {
            list[a[i][j]] += 1;
          }
        }
      } for (int j = 0; j < m; j++) {
          if (a[i][j] > 0) {
            list[a[i][j]] += 1;
          }
        } int j = 0; int j = 0; j 0 j < m j m j++ j++ j {
          if (a[i][j] > 0) {
            list[a[i][j]] += 1;
          }
        } {
          if (a[i][j] > 0) {
            list[a[i][j]] += 1;
          }
        } if (a[i][j] > 0) {
            list[a[i][j]] += 1;
          } a[i][j] > 0 a[i][j] a[i] a i j 0 {
            list[a[i][j]] += 1;
          } list[a[i][j]] += 1 list[a[i][j]] list a[i][j] a[i] a i j 1 int ans = 0; ans 0 for (int i = 0; i < m+1; i++) {
        if (list[i] == n) {
          ans++;
        }
      } int i = 0; int i = 0; i 0 i < m+1 i m+1 m 1 i++ i++ i {
        if (list[i] == n) {
          ans++;
        }
      } {
        if (list[i] == n) {
          ans++;
        }
      } if (list[i] == n) {
          ans++;
        } list[i] == n list[i] list i n {
          ans++;
        } ans++ ans System.out.println(ans) System.out.println System.out System System.out ans 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();
      int[][] a = new int[n][m];
      for (int i = 0; i < n; i++) {
        int k = sc.nextInt();
        for (int j = 0; j < k; j++) {
          a[i][j] = sc.nextInt();
        }
      }
      int[] list = new int[m+1];
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (a[i][j] > 0) {
            list[a[i][j]] += 1;
          }
        }
      }
      int ans = 0;
      for (int i = 0; i < m+1; i++) {
        if (list[i] == n) {
          ans++;
        }
      }
      System.out.println(ans);
    }
  } public 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];
      for (int i = 0; i < n; i++) {
        int k = sc.nextInt();
        for (int j = 0; j < k; j++) {
          a[i][j] = sc.nextInt();
        }
      }
      int[] list = new int[m+1];
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (a[i][j] > 0) {
            list[a[i][j]] += 1;
          }
        }
      }
      int ans = 0;
      for (int i = 0; i < m+1; i++) {
        if (list[i] == n) {
          ans++;
        }
      }
      System.out.println(ans);
    }
  } Main
import 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();
      int[][] a = new int[n][m];
      for (int i = 0; i < n; i++) {
        int k = sc.nextInt();
        for (int j = 0; j < k; j++) {
          a[i][j] = sc.nextInt();
        }
      }
      int[] list = new int[m+1];
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (a[i][j] > 0) {
            list[a[i][j]] += 1;
          }
        }
      }
      int ans = 0;
      for (int i = 0; i < m+1; i++) {
        if (list[i] == n) {
          ans++;
        }
      }
      System.out.println(ans);
    }
  }