import java.util.*;

public 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];
    BitSet all = new BitSet(m);
    all.flip(0, m);
    for (int i = 1; i <= n; i++) {
      k[i - 1] = scanner.nextInt();
      BitSet a = new BitSet();
      for (int j = 1; j <= k[i - 1]; j++) {
        a.set(scanner.nextInt() - 1);
      }
      all.and(a);
    }
    System.out.println(all.cardinality());
  }
} import java.util.*; util.* java public 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];
    BitSet all = new BitSet(m);
    all.flip(0, m);
    for (int i = 1; i <= n; i++) {
      k[i - 1] = scanner.nextInt();
      BitSet a = new BitSet();
      for (int j = 1; j <= k[i - 1]; j++) {
        a.set(scanner.nextInt() - 1);
      }
      all.and(a);
    }
    System.out.println(all.cardinality());
  }
} 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];
    BitSet all = new BitSet(m);
    all.flip(0, m);
    for (int i = 1; i <= n; i++) {
      k[i - 1] = scanner.nextInt();
      BitSet a = new BitSet();
      for (int j = 1; j <= k[i - 1]; j++) {
        a.set(scanner.nextInt() - 1);
      }
      all.and(a);
    }
    System.out.println(all.cardinality());
  } main {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int m = scanner.nextInt();
    int[] k = new int[n];
    BitSet all = new BitSet(m);
    all.flip(0, m);
    for (int i = 1; i <= n; i++) {
      k[i - 1] = scanner.nextInt();
      BitSet a = new BitSet();
      for (int j = 1; j <= k[i - 1]; j++) {
        a.set(scanner.nextInt() - 1);
      }
      all.and(a);
    }
    System.out.println(all.cardinality());
  } 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 BitSet all = new BitSet(m); all new BitSet(m) all.flip(0, m) all.flip all 0 m for (int i = 1; i <= n; i++) {
      k[i - 1] = scanner.nextInt();
      BitSet a = new BitSet();
      for (int j = 1; j <= k[i - 1]; j++) {
        a.set(scanner.nextInt() - 1);
      }
      all.and(a);
    } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
      k[i - 1] = scanner.nextInt();
      BitSet a = new BitSet();
      for (int j = 1; j <= k[i - 1]; j++) {
        a.set(scanner.nextInt() - 1);
      }
      all.and(a);
    } {
      k[i - 1] = scanner.nextInt();
      BitSet a = new BitSet();
      for (int j = 1; j <= k[i - 1]; j++) {
        a.set(scanner.nextInt() - 1);
      }
      all.and(a);
    } k[i - 1] = scanner.nextInt() k[i - 1] k i - 1 i 1 scanner.nextInt() scanner.nextInt scanner BitSet a = new BitSet(); a new BitSet() for (int j = 1; j <= k[i - 1]; j++) {
        a.set(scanner.nextInt() - 1);
      } int j = 1; int j = 1; j 1 j <= k[i - 1] j k[i - 1] k i - 1 i 1 j++ j++ j {
        a.set(scanner.nextInt() - 1);
      } {
        a.set(scanner.nextInt() - 1);
      } a.set(scanner.nextInt() - 1) a.set a scanner.nextInt() - 1 scanner.nextInt() scanner.nextInt scanner 1 all.and(a) all.and all a System.out.println(all.cardinality()) System.out.println System.out System System.out all.cardinality() all.cardinality all String[] args args public 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];
    BitSet all = new BitSet(m);
    all.flip(0, m);
    for (int i = 1; i <= n; i++) {
      k[i - 1] = scanner.nextInt();
      BitSet a = new BitSet();
      for (int j = 1; j <= k[i - 1]; j++) {
        a.set(scanner.nextInt() - 1);
      }
      all.and(a);
    }
    System.out.println(all.cardinality());
  }
} public 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];
    BitSet all = new BitSet(m);
    all.flip(0, m);
    for (int i = 1; i <= n; i++) {
      k[i - 1] = scanner.nextInt();
      BitSet a = new BitSet();
      for (int j = 1; j <= k[i - 1]; j++) {
        a.set(scanner.nextInt() - 1);
      }
      all.and(a);
    }
    System.out.println(all.cardinality());
  }
} Main
import java.util.*;

public 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];
    BitSet all = new BitSet(m);
    all.flip(0, m);
    for (int i = 1; i <= n; i++) {
      k[i - 1] = scanner.nextInt();
      BitSet a = new BitSet();
      for (int j = 1; j <= k[i - 1]; j++) {
        a.set(scanner.nextInt() - 1);
      }
      all.and(a);
    }
    System.out.println(all.cardinality());
  }
}