import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int m = scanner.nextInt();
    int[] k = new int[n];
    int[][] a = new int[n][m];
    for (int i = 0; i < n; i++) {
      k[i] = scanner.nextInt();
      for (int j = 0; j < k[i]; j++) {
        a[i][j] = scanner.nextInt();
      }
    }
    boolean[][] map = new boolean[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        map[i][j] = false;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < k[i]; j++) {
        map[i][a[i][j] - 1] = true;
      }
    }
    int count = 0;
    boolean isTrue;
    for (int i = 0; i < m; i++) {
      isTrue = true;
      for (int j = 0; j < n; j++) {
        if (!map[j][i]) {
          isTrue = false;
        }
      }
      if (isTrue) {
        count++;
      }
    }
    System.out.println(count);
  }

} import java.util.Scanner; Scanner java.util class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int m = scanner.nextInt();
    int[] k = new int[n];
    int[][] a = new int[n][m];
    for (int i = 0; i < n; i++) {
      k[i] = scanner.nextInt();
      for (int j = 0; j < k[i]; j++) {
        a[i][j] = scanner.nextInt();
      }
    }
    boolean[][] map = new boolean[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        map[i][j] = false;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < k[i]; j++) {
        map[i][a[i][j] - 1] = true;
      }
    }
    int count = 0;
    boolean isTrue;
    for (int i = 0; i < m; i++) {
      isTrue = true;
      for (int j = 0; j < n; j++) {
        if (!map[j][i]) {
          isTrue = false;
        }
      }
      if (isTrue) {
        count++;
      }
    }
    System.out.println(count);
  }

} Main public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int m = scanner.nextInt();
    int[] k = new int[n];
    int[][] a = new int[n][m];
    for (int i = 0; i < n; i++) {
      k[i] = scanner.nextInt();
      for (int j = 0; j < k[i]; j++) {
        a[i][j] = scanner.nextInt();
      }
    }
    boolean[][] map = new boolean[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        map[i][j] = false;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < k[i]; j++) {
        map[i][a[i][j] - 1] = true;
      }
    }
    int count = 0;
    boolean isTrue;
    for (int i = 0; i < m; i++) {
      isTrue = true;
      for (int j = 0; j < n; j++) {
        if (!map[j][i]) {
          isTrue = false;
        }
      }
      if (isTrue) {
        count++;
      }
    }
    System.out.println(count);
  } main {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int m = scanner.nextInt();
    int[] k = new int[n];
    int[][] a = new int[n][m];
    for (int i = 0; i < n; i++) {
      k[i] = scanner.nextInt();
      for (int j = 0; j < k[i]; j++) {
        a[i][j] = scanner.nextInt();
      }
    }
    boolean[][] map = new boolean[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        map[i][j] = false;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < k[i]; j++) {
        map[i][a[i][j] - 1] = true;
      }
    }
    int count = 0;
    boolean isTrue;
    for (int i = 0; i < m; i++) {
      isTrue = true;
      for (int j = 0; j < n; j++) {
        if (!map[j][i]) {
          isTrue = false;
        }
      }
      if (isTrue) {
        count++;
      }
    }
    System.out.println(count);
  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int m = scanner.nextInt(); m scanner.nextInt() scanner.nextInt scanner int[] k = new int[n]; k new int[n] n int[][] a = new int[n][m]; a new int[n][m] n m for (int i = 0; i < n; i++) {
      k[i] = scanner.nextInt();
      for (int j = 0; j < k[i]; j++) {
        a[i][j] = scanner.nextInt();
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      k[i] = scanner.nextInt();
      for (int j = 0; j < k[i]; j++) {
        a[i][j] = scanner.nextInt();
      }
    } {
      k[i] = scanner.nextInt();
      for (int j = 0; j < k[i]; j++) {
        a[i][j] = scanner.nextInt();
      }
    } k[i] = scanner.nextInt() k[i] k i scanner.nextInt() scanner.nextInt scanner for (int j = 0; j < k[i]; j++) {
        a[i][j] = scanner.nextInt();
      } int j = 0; int j = 0; j 0 j < k[i] j k[i] k i j++ j++ j {
        a[i][j] = scanner.nextInt();
      } {
        a[i][j] = scanner.nextInt();
      } a[i][j] = scanner.nextInt() a[i][j] a[i] a i j scanner.nextInt() scanner.nextInt scanner boolean[][] map = new boolean[n][m]; map new boolean[n][m] n m for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        map[i][j] = false;
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      for (int j = 0; j < m; j++) {
        map[i][j] = false;
      }
    } {
      for (int j = 0; j < m; j++) {
        map[i][j] = false;
      }
    } for (int j = 0; j < m; j++) {
        map[i][j] = false;
      } int j = 0; int j = 0; j 0 j < m j m j++ j++ j {
        map[i][j] = false;
      } {
        map[i][j] = false;
      } map[i][j] = false map[i][j] map[i] map i j false for (int i = 0; i < n; i++) {
      for (int j = 0; j < k[i]; j++) {
        map[i][a[i][j] - 1] = true;
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      for (int j = 0; j < k[i]; j++) {
        map[i][a[i][j] - 1] = true;
      }
    } {
      for (int j = 0; j < k[i]; j++) {
        map[i][a[i][j] - 1] = true;
      }
    } for (int j = 0; j < k[i]; j++) {
        map[i][a[i][j] - 1] = true;
      } int j = 0; int j = 0; j 0 j < k[i] j k[i] k i j++ j++ j {
        map[i][a[i][j] - 1] = true;
      } {
        map[i][a[i][j] - 1] = true;
      } map[i][a[i][j] - 1] = true map[i][a[i][j] - 1] map[i] map i a[i][j] - 1 a[i][j] a[i] a i j 1 true int count = 0; count 0 boolean isTrue; isTrue for (int i = 0; i < m; i++) {
      isTrue = true;
      for (int j = 0; j < n; j++) {
        if (!map[j][i]) {
          isTrue = false;
        }
      }
      if (isTrue) {
        count++;
      }
    } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
      isTrue = true;
      for (int j = 0; j < n; j++) {
        if (!map[j][i]) {
          isTrue = false;
        }
      }
      if (isTrue) {
        count++;
      }
    } {
      isTrue = true;
      for (int j = 0; j < n; j++) {
        if (!map[j][i]) {
          isTrue = false;
        }
      }
      if (isTrue) {
        count++;
      }
    } isTrue = true isTrue true for (int j = 0; j < n; j++) {
        if (!map[j][i]) {
          isTrue = false;
        }
      } int j = 0; int j = 0; j 0 j < n j n j++ j++ j {
        if (!map[j][i]) {
          isTrue = false;
        }
      } {
        if (!map[j][i]) {
          isTrue = false;
        }
      } if (!map[j][i]) {
          isTrue = false;
        } !map[j][i] map[j][i] map[j] map j i {
          isTrue = false;
        } isTrue = false isTrue false if (isTrue) {
        count++;
      } isTrue {
        count++;
      } count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int m = scanner.nextInt();
    int[] k = new int[n];
    int[][] a = new int[n][m];
    for (int i = 0; i < n; i++) {
      k[i] = scanner.nextInt();
      for (int j = 0; j < k[i]; j++) {
        a[i][j] = scanner.nextInt();
      }
    }
    boolean[][] map = new boolean[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        map[i][j] = false;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < k[i]; j++) {
        map[i][a[i][j] - 1] = true;
      }
    }
    int count = 0;
    boolean isTrue;
    for (int i = 0; i < m; i++) {
      isTrue = true;
      for (int j = 0; j < n; j++) {
        if (!map[j][i]) {
          isTrue = false;
        }
      }
      if (isTrue) {
        count++;
      }
    }
    System.out.println(count);
  }

}
