import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[][] K = new int[N][];
    for (int i = 0; i < N; i++) {
      int k = sc.nextInt();
      int[] a = new int[k];
      for (int j = 0; j < k; j++) {
        a[j] = sc.nextInt();
      }
      K[i] = a;
    }
    Main abc118B = new Main();
    System.out.println(abc118B.solve(M, K));
  }

  public int solve(int M, int[][] K) {
    ABC118BSolve abc118BSolve = new ABC118BSolve();
    return abc118BSolve.solve(M, K);
  }


  class ABC118BSolve {

    public int solve(int M, int[][] K) {
      Set<Integer> set = arrayToSet(K[0]);
      for(int i = 1; i < K.length; i++ ){
        int[] a = new int[30];
        for(int j = 0; j < K[i].length; j++ ){
          a[K[i][j] - 1] = 1;
        }
        Set<Integer> nextSet = new HashSet();
        Iterator<Integer> it = set.iterator();
        while(it.hasNext()) {
          Integer next = it.next();
          if(a[next-1] == 1) nextSet.add(next);
        }
        set = nextSet;
      }
      return set.size();
    }
  }

  private Set<Integer> arrayToSet(int[] k) {
    Set<Integer> set = new HashSet();
    for(int i = 0; i < k.length; i++ ){
      set.add(k[i]);
    }
    return set;
  }
} import java.util.HashSet; HashSet java.util import java.util.Iterator; Iterator java.util import java.util.Scanner; Scanner java.util import java.util.Set; Set 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[][] K = new int[N][];
    for (int i = 0; i < N; i++) {
      int k = sc.nextInt();
      int[] a = new int[k];
      for (int j = 0; j < k; j++) {
        a[j] = sc.nextInt();
      }
      K[i] = a;
    }
    Main abc118B = new Main();
    System.out.println(abc118B.solve(M, K));
  }

  public int solve(int M, int[][] K) {
    ABC118BSolve abc118BSolve = new ABC118BSolve();
    return abc118BSolve.solve(M, K);
  }


  class ABC118BSolve {

    public int solve(int M, int[][] K) {
      Set<Integer> set = arrayToSet(K[0]);
      for(int i = 1; i < K.length; i++ ){
        int[] a = new int[30];
        for(int j = 0; j < K[i].length; j++ ){
          a[K[i][j] - 1] = 1;
        }
        Set<Integer> nextSet = new HashSet();
        Iterator<Integer> it = set.iterator();
        while(it.hasNext()) {
          Integer next = it.next();
          if(a[next-1] == 1) nextSet.add(next);
        }
        set = nextSet;
      }
      return set.size();
    }
  }

  private Set<Integer> arrayToSet(int[] k) {
    Set<Integer> set = new HashSet();
    for(int i = 0; i < k.length; i++ ){
      set.add(k[i]);
    }
    return set;
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[][] K = new int[N][];
    for (int i = 0; i < N; i++) {
      int k = sc.nextInt();
      int[] a = new int[k];
      for (int j = 0; j < k; j++) {
        a[j] = sc.nextInt();
      }
      K[i] = a;
    }
    Main abc118B = new Main();
    System.out.println(abc118B.solve(M, K));
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[][] K = new int[N][];
    for (int i = 0; i < N; i++) {
      int k = sc.nextInt();
      int[] a = new int[k];
      for (int j = 0; j < k; j++) {
        a[j] = sc.nextInt();
      }
      K[i] = a;
    }
    Main abc118B = new Main();
    System.out.println(abc118B.solve(M, K));
  } 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[][] K = new int[N][]; K new int[N][] N for (int i = 0; i < N; i++) {
      int k = sc.nextInt();
      int[] a = new int[k];
      for (int j = 0; j < k; j++) {
        a[j] = sc.nextInt();
      }
      K[i] = a;
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      int k = sc.nextInt();
      int[] a = new int[k];
      for (int j = 0; j < k; j++) {
        a[j] = sc.nextInt();
      }
      K[i] = a;
    } {
      int k = sc.nextInt();
      int[] a = new int[k];
      for (int j = 0; j < k; j++) {
        a[j] = sc.nextInt();
      }
      K[i] = a;
    } int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc int[] a = new int[k]; a new int[k] k for (int j = 0; j < k; j++) {
        a[j] = sc.nextInt();
      } int j = 0; int j = 0; j 0 j < k j k j++ j++ j {
        a[j] = sc.nextInt();
      } {
        a[j] = sc.nextInt();
      } a[j] = sc.nextInt() a[j] a j sc.nextInt() sc.nextInt sc K[i] = a K[i] K i a Main abc118B = new Main(); abc118B new Main() System.out.println(abc118B.solve(M, K)) System.out.println System.out System System.out abc118B.solve(M, K) abc118B.solve abc118B M K String[] args args public int solve(int M, int[][] K) {
    ABC118BSolve abc118BSolve = new ABC118BSolve();
    return abc118BSolve.solve(M, K);
  } solve {
    ABC118BSolve abc118BSolve = new ABC118BSolve();
    return abc118BSolve.solve(M, K);
  } ABC118BSolve abc118BSolve = new ABC118BSolve(); abc118BSolve new ABC118BSolve() return abc118BSolve.solve(M, K); abc118BSolve.solve(M, K) abc118BSolve.solve abc118BSolve M K int M M int[][] K K private Set<Integer> arrayToSet(int[] k) {
    Set<Integer> set = new HashSet();
    for(int i = 0; i < k.length; i++ ){
      set.add(k[i]);
    }
    return set;
  } arrayToSet {
    Set<Integer> set = new HashSet();
    for(int i = 0; i < k.length; i++ ){
      set.add(k[i]);
    }
    return set;
  } Set<Integer> set = new HashSet(); set new HashSet() for(int i = 0; i < k.length; i++ ){
      set.add(k[i]);
    } int i = 0; int i = 0; i 0 i < k.length i k.length k k.length i++ i++ i {
      set.add(k[i]);
    } {
      set.add(k[i]);
    } set.add(k[i]) set.add set k[i] k i return set; set int[] k k class ABC118BSolve {

    public int solve(int M, int[][] K) {
      Set<Integer> set = arrayToSet(K[0]);
      for(int i = 1; i < K.length; i++ ){
        int[] a = new int[30];
        for(int j = 0; j < K[i].length; j++ ){
          a[K[i][j] - 1] = 1;
        }
        Set<Integer> nextSet = new HashSet();
        Iterator<Integer> it = set.iterator();
        while(it.hasNext()) {
          Integer next = it.next();
          if(a[next-1] == 1) nextSet.add(next);
        }
        set = nextSet;
      }
      return set.size();
    }
  } ABC118BSolve public int solve(int M, int[][] K) {
      Set<Integer> set = arrayToSet(K[0]);
      for(int i = 1; i < K.length; i++ ){
        int[] a = new int[30];
        for(int j = 0; j < K[i].length; j++ ){
          a[K[i][j] - 1] = 1;
        }
        Set<Integer> nextSet = new HashSet();
        Iterator<Integer> it = set.iterator();
        while(it.hasNext()) {
          Integer next = it.next();
          if(a[next-1] == 1) nextSet.add(next);
        }
        set = nextSet;
      }
      return set.size();
    } solve {
      Set<Integer> set = arrayToSet(K[0]);
      for(int i = 1; i < K.length; i++ ){
        int[] a = new int[30];
        for(int j = 0; j < K[i].length; j++ ){
          a[K[i][j] - 1] = 1;
        }
        Set<Integer> nextSet = new HashSet();
        Iterator<Integer> it = set.iterator();
        while(it.hasNext()) {
          Integer next = it.next();
          if(a[next-1] == 1) nextSet.add(next);
        }
        set = nextSet;
      }
      return set.size();
    } Set<Integer> set = arrayToSet(K[0]); set arrayToSet(K[0]) arrayToSet K[0] K 0 for(int i = 1; i < K.length; i++ ){
        int[] a = new int[30];
        for(int j = 0; j < K[i].length; j++ ){
          a[K[i][j] - 1] = 1;
        }
        Set<Integer> nextSet = new HashSet();
        Iterator<Integer> it = set.iterator();
        while(it.hasNext()) {
          Integer next = it.next();
          if(a[next-1] == 1) nextSet.add(next);
        }
        set = nextSet;
      } int i = 1; int i = 1; i 1 i < K.length i K.length K K.length i++ i++ i {
        int[] a = new int[30];
        for(int j = 0; j < K[i].length; j++ ){
          a[K[i][j] - 1] = 1;
        }
        Set<Integer> nextSet = new HashSet();
        Iterator<Integer> it = set.iterator();
        while(it.hasNext()) {
          Integer next = it.next();
          if(a[next-1] == 1) nextSet.add(next);
        }
        set = nextSet;
      } {
        int[] a = new int[30];
        for(int j = 0; j < K[i].length; j++ ){
          a[K[i][j] - 1] = 1;
        }
        Set<Integer> nextSet = new HashSet();
        Iterator<Integer> it = set.iterator();
        while(it.hasNext()) {
          Integer next = it.next();
          if(a[next-1] == 1) nextSet.add(next);
        }
        set = nextSet;
      } int[] a = new int[30]; a new int[30] 30 for(int j = 0; j < K[i].length; j++ ){
          a[K[i][j] - 1] = 1;
        } int j = 0; int j = 0; j 0 j < K[i].length j K[i].length K[i] K i K[i].length j++ j++ j {
          a[K[i][j] - 1] = 1;
        } {
          a[K[i][j] - 1] = 1;
        } a[K[i][j] - 1] = 1 a[K[i][j] - 1] a K[i][j] - 1 K[i][j] K[i] K i j 1 1 Set<Integer> nextSet = new HashSet(); nextSet new HashSet() Iterator<Integer> it = set.iterator(); it set.iterator() set.iterator set while(it.hasNext()) {
          Integer next = it.next();
          if(a[next-1] == 1) nextSet.add(next);
        } it.hasNext() it.hasNext it {
          Integer next = it.next();
          if(a[next-1] == 1) nextSet.add(next);
        } Integer next = it.next(); next it.next() it.next it if(a[next-1] == 1) nextSet.add(next); a[next-1] == 1 a[next-1] a next-1 next 1 1 nextSet.add(next) nextSet.add nextSet next set = nextSet set nextSet return set.size(); set.size() set.size set int M M int[][] K K public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[][] K = new int[N][];
    for (int i = 0; i < N; i++) {
      int k = sc.nextInt();
      int[] a = new int[k];
      for (int j = 0; j < k; j++) {
        a[j] = sc.nextInt();
      }
      K[i] = a;
    }
    Main abc118B = new Main();
    System.out.println(abc118B.solve(M, K));
  }

  public int solve(int M, int[][] K) {
    ABC118BSolve abc118BSolve = new ABC118BSolve();
    return abc118BSolve.solve(M, K);
  }


  class ABC118BSolve {

    public int solve(int M, int[][] K) {
      Set<Integer> set = arrayToSet(K[0]);
      for(int i = 1; i < K.length; i++ ){
        int[] a = new int[30];
        for(int j = 0; j < K[i].length; j++ ){
          a[K[i][j] - 1] = 1;
        }
        Set<Integer> nextSet = new HashSet();
        Iterator<Integer> it = set.iterator();
        while(it.hasNext()) {
          Integer next = it.next();
          if(a[next-1] == 1) nextSet.add(next);
        }
        set = nextSet;
      }
      return set.size();
    }
  }

  private Set<Integer> arrayToSet(int[] k) {
    Set<Integer> set = new HashSet();
    for(int i = 0; i < k.length; i++ ){
      set.add(k[i]);
    }
    return set;
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[][] K = new int[N][];
    for (int i = 0; i < N; i++) {
      int k = sc.nextInt();
      int[] a = new int[k];
      for (int j = 0; j < k; j++) {
        a[j] = sc.nextInt();
      }
      K[i] = a;
    }
    Main abc118B = new Main();
    System.out.println(abc118B.solve(M, K));
  }

  public int solve(int M, int[][] K) {
    ABC118BSolve abc118BSolve = new ABC118BSolve();
    return abc118BSolve.solve(M, K);
  }


  class ABC118BSolve {

    public int solve(int M, int[][] K) {
      Set<Integer> set = arrayToSet(K[0]);
      for(int i = 1; i < K.length; i++ ){
        int[] a = new int[30];
        for(int j = 0; j < K[i].length; j++ ){
          a[K[i][j] - 1] = 1;
        }
        Set<Integer> nextSet = new HashSet();
        Iterator<Integer> it = set.iterator();
        while(it.hasNext()) {
          Integer next = it.next();
          if(a[next-1] == 1) nextSet.add(next);
        }
        set = nextSet;
      }
      return set.size();
    }
  }

  private Set<Integer> arrayToSet(int[] k) {
    Set<Integer> set = new HashSet();
    for(int i = 0; i < k.length; i++ ){
      set.add(k[i]);
    }
    return set;
  }
} Main
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[][] K = new int[N][];
    for (int i = 0; i < N; i++) {
      int k = sc.nextInt();
      int[] a = new int[k];
      for (int j = 0; j < k; j++) {
        a[j] = sc.nextInt();
      }
      K[i] = a;
    }
    Main abc118B = new Main();
    System.out.println(abc118B.solve(M, K));
  }

  public int solve(int M, int[][] K) {
    ABC118BSolve abc118BSolve = new ABC118BSolve();
    return abc118BSolve.solve(M, K);
  }


  class ABC118BSolve {

    public int solve(int M, int[][] K) {
      Set<Integer> set = arrayToSet(K[0]);
      for(int i = 1; i < K.length; i++ ){
        int[] a = new int[30];
        for(int j = 0; j < K[i].length; j++ ){
          a[K[i][j] - 1] = 1;
        }
        Set<Integer> nextSet = new HashSet();
        Iterator<Integer> it = set.iterator();
        while(it.hasNext()) {
          Integer next = it.next();
          if(a[next-1] == 1) nextSet.add(next);
        }
        set = nextSet;
      }
      return set.size();
    }
  }

  private Set<Integer> arrayToSet(int[] k) {
    Set<Integer> set = new HashSet();
    for(int i = 0; i < k.length; i++ ){
      set.add(k[i]);
    }
    return set;
  }
}
