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 mat[][] = new int[N][M];
    for(int i=0;i<N;i++){
     int tmp = sc.nextInt();
      for(int j=0;j<tmp;j++){
        mat[i][j]=sc.nextInt();
      }
    }
    int answer = 0;
    for(int i=1;i<=M;i++){
      if(isAllLike(mat,i,N,M)){
        answer = answer +1;
      }
    }


    System.out.println(answer);
    
  }
  
  //食べ物Xが全員好きか判定するメソッド
  public static boolean isAllLike(int mat[][],int x,int N , int M){
      boolean isLike = false;
    for(int i=0;i<N;i++){
      for(int j=0;j<M;j++){
        if(mat[i][j]==x){
          isLike = true;
        }
      }
      if(!isLike){
        return false;
      }
      isLike = false;
    }
    return true;
  }
  

  
} 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 mat[][] = new int[N][M];
    for(int i=0;i<N;i++){
     int tmp = sc.nextInt();
      for(int j=0;j<tmp;j++){
        mat[i][j]=sc.nextInt();
      }
    }
    int answer = 0;
    for(int i=1;i<=M;i++){
      if(isAllLike(mat,i,N,M)){
        answer = answer +1;
      }
    }


    System.out.println(answer);
    
  }
  
  //食べ物Xが全員好きか判定するメソッド
  public static boolean isAllLike(int mat[][],int x,int N , int M){
      boolean isLike = false;
    for(int i=0;i<N;i++){
      for(int j=0;j<M;j++){
        if(mat[i][j]==x){
          isLike = true;
        }
      }
      if(!isLike){
        return false;
      }
      isLike = false;
    }
    return true;
  }
  

  
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int mat[][] = new int[N][M];
    for(int i=0;i<N;i++){
     int tmp = sc.nextInt();
      for(int j=0;j<tmp;j++){
        mat[i][j]=sc.nextInt();
      }
    }
    int answer = 0;
    for(int i=1;i<=M;i++){
      if(isAllLike(mat,i,N,M)){
        answer = answer +1;
      }
    }


    System.out.println(answer);
    
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int mat[][] = new int[N][M];
    for(int i=0;i<N;i++){
     int tmp = sc.nextInt();
      for(int j=0;j<tmp;j++){
        mat[i][j]=sc.nextInt();
      }
    }
    int answer = 0;
    for(int i=1;i<=M;i++){
      if(isAllLike(mat,i,N,M)){
        answer = answer +1;
      }
    }


    System.out.println(answer);
    
  } 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 mat[][] = new int[N][M]; mat new int[N][M] N M for(int i=0;i<N;i++){
     int tmp = sc.nextInt();
      for(int j=0;j<tmp;j++){
        mat[i][j]=sc.nextInt();
      }
    } int i=0; int i=0; i 0 i<N i N i++ i++ i {
     int tmp = sc.nextInt();
      for(int j=0;j<tmp;j++){
        mat[i][j]=sc.nextInt();
      }
    } {
     int tmp = sc.nextInt();
      for(int j=0;j<tmp;j++){
        mat[i][j]=sc.nextInt();
      }
    } int tmp = sc.nextInt(); tmp sc.nextInt() sc.nextInt sc for(int j=0;j<tmp;j++){
        mat[i][j]=sc.nextInt();
      } int j=0; int j=0; j 0 j<tmp j tmp j++ j++ j {
        mat[i][j]=sc.nextInt();
      } {
        mat[i][j]=sc.nextInt();
      } mat[i][j]=sc.nextInt() mat[i][j] mat[i] mat i j sc.nextInt() sc.nextInt sc int answer = 0; answer 0 for(int i=1;i<=M;i++){
      if(isAllLike(mat,i,N,M)){
        answer = answer +1;
      }
    } int i=1; int i=1; i 1 i<=M i M i++ i++ i {
      if(isAllLike(mat,i,N,M)){
        answer = answer +1;
      }
    } {
      if(isAllLike(mat,i,N,M)){
        answer = answer +1;
      }
    } if(isAllLike(mat,i,N,M)){
        answer = answer +1;
      } isAllLike(mat,i,N,M) isAllLike mat i N M {
        answer = answer +1;
      } answer = answer +1 answer answer +1 answer 1 System.out.println(answer) System.out.println System.out System System.out answer String[] args args //食べ物Xが全員好きか判定するメソッド
  public static boolean isAllLike(int mat[][],int x,int N , int M){
      boolean isLike = false;
    for(int i=0;i<N;i++){
      for(int j=0;j<M;j++){
        if(mat[i][j]==x){
          isLike = true;
        }
      }
      if(!isLike){
        return false;
      }
      isLike = false;
    }
    return true;
  } isAllLike {
      boolean isLike = false;
    for(int i=0;i<N;i++){
      for(int j=0;j<M;j++){
        if(mat[i][j]==x){
          isLike = true;
        }
      }
      if(!isLike){
        return false;
      }
      isLike = false;
    }
    return true;
  } boolean isLike = false; isLike false for(int i=0;i<N;i++){
      for(int j=0;j<M;j++){
        if(mat[i][j]==x){
          isLike = true;
        }
      }
      if(!isLike){
        return false;
      }
      isLike = false;
    } int i=0; int i=0; i 0 i<N i N i++ i++ i {
      for(int j=0;j<M;j++){
        if(mat[i][j]==x){
          isLike = true;
        }
      }
      if(!isLike){
        return false;
      }
      isLike = false;
    } {
      for(int j=0;j<M;j++){
        if(mat[i][j]==x){
          isLike = true;
        }
      }
      if(!isLike){
        return false;
      }
      isLike = false;
    } for(int j=0;j<M;j++){
        if(mat[i][j]==x){
          isLike = true;
        }
      } int j=0; int j=0; j 0 j<M j M j++ j++ j {
        if(mat[i][j]==x){
          isLike = true;
        }
      } {
        if(mat[i][j]==x){
          isLike = true;
        }
      } if(mat[i][j]==x){
          isLike = true;
        } mat[i][j]==x mat[i][j] mat[i] mat i j x {
          isLike = true;
        } isLike = true isLike true if(!isLike){
        return false;
      } !isLike isLike {
        return false;
      } return false; false isLike = false isLike false return true; true int mat[][] mat int x x int N N int M M public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int mat[][] = new int[N][M];
    for(int i=0;i<N;i++){
     int tmp = sc.nextInt();
      for(int j=0;j<tmp;j++){
        mat[i][j]=sc.nextInt();
      }
    }
    int answer = 0;
    for(int i=1;i<=M;i++){
      if(isAllLike(mat,i,N,M)){
        answer = answer +1;
      }
    }


    System.out.println(answer);
    
  }
  
  //食べ物Xが全員好きか判定するメソッド
  public static boolean isAllLike(int mat[][],int x,int N , int M){
      boolean isLike = false;
    for(int i=0;i<N;i++){
      for(int j=0;j<M;j++){
        if(mat[i][j]==x){
          isLike = true;
        }
      }
      if(!isLike){
        return false;
      }
      isLike = false;
    }
    return true;
  }
  

  
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int mat[][] = new int[N][M];
    for(int i=0;i<N;i++){
     int tmp = sc.nextInt();
      for(int j=0;j<tmp;j++){
        mat[i][j]=sc.nextInt();
      }
    }
    int answer = 0;
    for(int i=1;i<=M;i++){
      if(isAllLike(mat,i,N,M)){
        answer = answer +1;
      }
    }


    System.out.println(answer);
    
  }
  
  //食べ物Xが全員好きか判定するメソッド
  public static boolean isAllLike(int mat[][],int x,int N , int M){
      boolean isLike = false;
    for(int i=0;i<N;i++){
      for(int j=0;j<M;j++){
        if(mat[i][j]==x){
          isLike = true;
        }
      }
      if(!isLike){
        return false;
      }
      isLike = false;
    }
    return true;
  }
  

  
} 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 mat[][] = new int[N][M];
    for(int i=0;i<N;i++){
     int tmp = sc.nextInt();
      for(int j=0;j<tmp;j++){
        mat[i][j]=sc.nextInt();
      }
    }
    int answer = 0;
    for(int i=1;i<=M;i++){
      if(isAllLike(mat,i,N,M)){
        answer = answer +1;
      }
    }


    System.out.println(answer);
    
  }
  
  //食べ物Xが全員好きか判定するメソッド
  public static boolean isAllLike(int mat[][],int x,int N , int M){
      boolean isLike = false;
    for(int i=0;i<N;i++){
      for(int j=0;j<M;j++){
        if(mat[i][j]==x){
          isLike = true;
        }
      }
      if(!isLike){
        return false;
      }
      isLike = false;
    }
    return true;
  }
  

  
}