import java.util.*;
import java.util.ArrayList;
import java.util.Collections;

public class Main{
  
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    
    if(N == 1){
      int count1 = 0;
      int K1 = sc.nextInt();
      for(int i = 0; i < K1 ; i++){
        int love = sc.nextInt();
        if(love <= M){
          count1++;
        }
      }
      
      System.out.println(count1);
      
    }else{
    
    ArrayList<Integer> love = new ArrayList<Integer>();
    for(int i = 0; i < N ; i++){
      int K = sc.nextInt();
      int[] list = new int[K];
       for(int j = 0; j < K ; j++){
         list[j] = sc.nextInt();
         love.add(list[j]);
       }   
    }
      
    Collections.sort(love);
 
    ArrayList<Integer> countAll = new ArrayList<Integer>();
    int count = 0;
    for(int i = 1; i <= M  ; i++){
      for(int j = 0; j < love.size(); j++){
        int jd = love.get(j);
        if(jd == i){
          count = count + 1;
        }
      }
      countAll.add(count);
      count = 0;
    }
      
    int lastCount = 0;
    for(int i = 0; i < countAll.size() ; i++){
      if(countAll.get(i) == N){
        lastCount++;
      }
    }
    System.out.println(lastCount);   
    }
  }  
} import java.util.*; util.* java import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections 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();
    
    if(N == 1){
      int count1 = 0;
      int K1 = sc.nextInt();
      for(int i = 0; i < K1 ; i++){
        int love = sc.nextInt();
        if(love <= M){
          count1++;
        }
      }
      
      System.out.println(count1);
      
    }else{
    
    ArrayList<Integer> love = new ArrayList<Integer>();
    for(int i = 0; i < N ; i++){
      int K = sc.nextInt();
      int[] list = new int[K];
       for(int j = 0; j < K ; j++){
         list[j] = sc.nextInt();
         love.add(list[j]);
       }   
    }
      
    Collections.sort(love);
 
    ArrayList<Integer> countAll = new ArrayList<Integer>();
    int count = 0;
    for(int i = 1; i <= M  ; i++){
      for(int j = 0; j < love.size(); j++){
        int jd = love.get(j);
        if(jd == i){
          count = count + 1;
        }
      }
      countAll.add(count);
      count = 0;
    }
      
    int lastCount = 0;
    for(int i = 0; i < countAll.size() ; i++){
      if(countAll.get(i) == N){
        lastCount++;
      }
    }
    System.out.println(lastCount);   
    }
  }  
} Main public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    
    if(N == 1){
      int count1 = 0;
      int K1 = sc.nextInt();
      for(int i = 0; i < K1 ; i++){
        int love = sc.nextInt();
        if(love <= M){
          count1++;
        }
      }
      
      System.out.println(count1);
      
    }else{
    
    ArrayList<Integer> love = new ArrayList<Integer>();
    for(int i = 0; i < N ; i++){
      int K = sc.nextInt();
      int[] list = new int[K];
       for(int j = 0; j < K ; j++){
         list[j] = sc.nextInt();
         love.add(list[j]);
       }   
    }
      
    Collections.sort(love);
 
    ArrayList<Integer> countAll = new ArrayList<Integer>();
    int count = 0;
    for(int i = 1; i <= M  ; i++){
      for(int j = 0; j < love.size(); j++){
        int jd = love.get(j);
        if(jd == i){
          count = count + 1;
        }
      }
      countAll.add(count);
      count = 0;
    }
      
    int lastCount = 0;
    for(int i = 0; i < countAll.size() ; i++){
      if(countAll.get(i) == N){
        lastCount++;
      }
    }
    System.out.println(lastCount);   
    }
  } main {
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    
    if(N == 1){
      int count1 = 0;
      int K1 = sc.nextInt();
      for(int i = 0; i < K1 ; i++){
        int love = sc.nextInt();
        if(love <= M){
          count1++;
        }
      }
      
      System.out.println(count1);
      
    }else{
    
    ArrayList<Integer> love = new ArrayList<Integer>();
    for(int i = 0; i < N ; i++){
      int K = sc.nextInt();
      int[] list = new int[K];
       for(int j = 0; j < K ; j++){
         list[j] = sc.nextInt();
         love.add(list[j]);
       }   
    }
      
    Collections.sort(love);
 
    ArrayList<Integer> countAll = new ArrayList<Integer>();
    int count = 0;
    for(int i = 1; i <= M  ; i++){
      for(int j = 0; j < love.size(); j++){
        int jd = love.get(j);
        if(jd == i){
          count = count + 1;
        }
      }
      countAll.add(count);
      count = 0;
    }
      
    int lastCount = 0;
    for(int i = 0; i < countAll.size() ; i++){
      if(countAll.get(i) == N){
        lastCount++;
      }
    }
    System.out.println(lastCount);   
    }
  } 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 if(N == 1){
      int count1 = 0;
      int K1 = sc.nextInt();
      for(int i = 0; i < K1 ; i++){
        int love = sc.nextInt();
        if(love <= M){
          count1++;
        }
      }
      
      System.out.println(count1);
      
    }else{
    
    ArrayList<Integer> love = new ArrayList<Integer>();
    for(int i = 0; i < N ; i++){
      int K = sc.nextInt();
      int[] list = new int[K];
       for(int j = 0; j < K ; j++){
         list[j] = sc.nextInt();
         love.add(list[j]);
       }   
    }
      
    Collections.sort(love);
 
    ArrayList<Integer> countAll = new ArrayList<Integer>();
    int count = 0;
    for(int i = 1; i <= M  ; i++){
      for(int j = 0; j < love.size(); j++){
        int jd = love.get(j);
        if(jd == i){
          count = count + 1;
        }
      }
      countAll.add(count);
      count = 0;
    }
      
    int lastCount = 0;
    for(int i = 0; i < countAll.size() ; i++){
      if(countAll.get(i) == N){
        lastCount++;
      }
    }
    System.out.println(lastCount);   
    } N == 1 N 1 {
      int count1 = 0;
      int K1 = sc.nextInt();
      for(int i = 0; i < K1 ; i++){
        int love = sc.nextInt();
        if(love <= M){
          count1++;
        }
      }
      
      System.out.println(count1);
      
    } int count1 = 0; count1 0 int K1 = sc.nextInt(); K1 sc.nextInt() sc.nextInt sc for(int i = 0; i < K1 ; i++){
        int love = sc.nextInt();
        if(love <= M){
          count1++;
        }
      } int i = 0; int i = 0; i 0 i < K1 i K1 i++ i++ i {
        int love = sc.nextInt();
        if(love <= M){
          count1++;
        }
      } {
        int love = sc.nextInt();
        if(love <= M){
          count1++;
        }
      } int love = sc.nextInt(); love sc.nextInt() sc.nextInt sc if(love <= M){
          count1++;
        } love <= M love M {
          count1++;
        } count1++ count1 System.out.println(count1) System.out.println System.out System System.out count1 {
    
    ArrayList<Integer> love = new ArrayList<Integer>();
    for(int i = 0; i < N ; i++){
      int K = sc.nextInt();
      int[] list = new int[K];
       for(int j = 0; j < K ; j++){
         list[j] = sc.nextInt();
         love.add(list[j]);
       }   
    }
      
    Collections.sort(love);
 
    ArrayList<Integer> countAll = new ArrayList<Integer>();
    int count = 0;
    for(int i = 1; i <= M  ; i++){
      for(int j = 0; j < love.size(); j++){
        int jd = love.get(j);
        if(jd == i){
          count = count + 1;
        }
      }
      countAll.add(count);
      count = 0;
    }
      
    int lastCount = 0;
    for(int i = 0; i < countAll.size() ; i++){
      if(countAll.get(i) == N){
        lastCount++;
      }
    }
    System.out.println(lastCount);   
    } ArrayList<Integer> love = new ArrayList<Integer>(); love new ArrayList<Integer>() for(int i = 0; i < N ; i++){
      int K = sc.nextInt();
      int[] list = new int[K];
       for(int j = 0; j < K ; j++){
         list[j] = sc.nextInt();
         love.add(list[j]);
       }   
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      int K = sc.nextInt();
      int[] list = new int[K];
       for(int j = 0; j < K ; j++){
         list[j] = sc.nextInt();
         love.add(list[j]);
       }   
    } {
      int K = sc.nextInt();
      int[] list = new int[K];
       for(int j = 0; j < K ; j++){
         list[j] = sc.nextInt();
         love.add(list[j]);
       }   
    } int K = sc.nextInt(); K sc.nextInt() sc.nextInt sc int[] list = new int[K]; list new int[K] K for(int j = 0; j < K ; j++){
         list[j] = sc.nextInt();
         love.add(list[j]);
       } int j = 0; int j = 0; j 0 j < K j K j++ j++ j {
         list[j] = sc.nextInt();
         love.add(list[j]);
       } {
         list[j] = sc.nextInt();
         love.add(list[j]);
       } list[j] = sc.nextInt() list[j] list j sc.nextInt() sc.nextInt sc love.add(list[j]) love.add love list[j] list j Collections.sort(love) Collections.sort Collections love ArrayList<Integer> countAll = new ArrayList<Integer>(); countAll new ArrayList<Integer>() int count = 0; count 0 for(int i = 1; i <= M  ; i++){
      for(int j = 0; j < love.size(); j++){
        int jd = love.get(j);
        if(jd == i){
          count = count + 1;
        }
      }
      countAll.add(count);
      count = 0;
    } int i = 1; int i = 1; i 1 i <= M i M i++ i++ i {
      for(int j = 0; j < love.size(); j++){
        int jd = love.get(j);
        if(jd == i){
          count = count + 1;
        }
      }
      countAll.add(count);
      count = 0;
    } {
      for(int j = 0; j < love.size(); j++){
        int jd = love.get(j);
        if(jd == i){
          count = count + 1;
        }
      }
      countAll.add(count);
      count = 0;
    } for(int j = 0; j < love.size(); j++){
        int jd = love.get(j);
        if(jd == i){
          count = count + 1;
        }
      } int j = 0; int j = 0; j 0 j < love.size() j love.size() love.size love j++ j++ j {
        int jd = love.get(j);
        if(jd == i){
          count = count + 1;
        }
      } {
        int jd = love.get(j);
        if(jd == i){
          count = count + 1;
        }
      } int jd = love.get(j); jd love.get(j) love.get love j if(jd == i){
          count = count + 1;
        } jd == i jd i {
          count = count + 1;
        } count = count + 1 count count + 1 count 1 countAll.add(count) countAll.add countAll count count = 0 count 0 int lastCount = 0; lastCount 0 for(int i = 0; i < countAll.size() ; i++){
      if(countAll.get(i) == N){
        lastCount++;
      }
    } int i = 0; int i = 0; i 0 i < countAll.size() i countAll.size() countAll.size countAll i++ i++ i {
      if(countAll.get(i) == N){
        lastCount++;
      }
    } {
      if(countAll.get(i) == N){
        lastCount++;
      }
    } if(countAll.get(i) == N){
        lastCount++;
      } countAll.get(i) == N countAll.get(i) countAll.get countAll i N {
        lastCount++;
      } lastCount++ lastCount System.out.println(lastCount) System.out.println System.out System System.out lastCount 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();
    
    if(N == 1){
      int count1 = 0;
      int K1 = sc.nextInt();
      for(int i = 0; i < K1 ; i++){
        int love = sc.nextInt();
        if(love <= M){
          count1++;
        }
      }
      
      System.out.println(count1);
      
    }else{
    
    ArrayList<Integer> love = new ArrayList<Integer>();
    for(int i = 0; i < N ; i++){
      int K = sc.nextInt();
      int[] list = new int[K];
       for(int j = 0; j < K ; j++){
         list[j] = sc.nextInt();
         love.add(list[j]);
       }   
    }
      
    Collections.sort(love);
 
    ArrayList<Integer> countAll = new ArrayList<Integer>();
    int count = 0;
    for(int i = 1; i <= M  ; i++){
      for(int j = 0; j < love.size(); j++){
        int jd = love.get(j);
        if(jd == i){
          count = count + 1;
        }
      }
      countAll.add(count);
      count = 0;
    }
      
    int lastCount = 0;
    for(int i = 0; i < countAll.size() ; i++){
      if(countAll.get(i) == N){
        lastCount++;
      }
    }
    System.out.println(lastCount);   
    }
  }  
} public class Main{
  
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    
    if(N == 1){
      int count1 = 0;
      int K1 = sc.nextInt();
      for(int i = 0; i < K1 ; i++){
        int love = sc.nextInt();
        if(love <= M){
          count1++;
        }
      }
      
      System.out.println(count1);
      
    }else{
    
    ArrayList<Integer> love = new ArrayList<Integer>();
    for(int i = 0; i < N ; i++){
      int K = sc.nextInt();
      int[] list = new int[K];
       for(int j = 0; j < K ; j++){
         list[j] = sc.nextInt();
         love.add(list[j]);
       }   
    }
      
    Collections.sort(love);
 
    ArrayList<Integer> countAll = new ArrayList<Integer>();
    int count = 0;
    for(int i = 1; i <= M  ; i++){
      for(int j = 0; j < love.size(); j++){
        int jd = love.get(j);
        if(jd == i){
          count = count + 1;
        }
      }
      countAll.add(count);
      count = 0;
    }
      
    int lastCount = 0;
    for(int i = 0; i < countAll.size() ; i++){
      if(countAll.get(i) == N){
        lastCount++;
      }
    }
    System.out.println(lastCount);   
    }
  }  
} Main
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;

public class Main{
  
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    
    if(N == 1){
      int count1 = 0;
      int K1 = sc.nextInt();
      for(int i = 0; i < K1 ; i++){
        int love = sc.nextInt();
        if(love <= M){
          count1++;
        }
      }
      
      System.out.println(count1);
      
    }else{
    
    ArrayList<Integer> love = new ArrayList<Integer>();
    for(int i = 0; i < N ; i++){
      int K = sc.nextInt();
      int[] list = new int[K];
       for(int j = 0; j < K ; j++){
         list[j] = sc.nextInt();
         love.add(list[j]);
       }   
    }
      
    Collections.sort(love);
 
    ArrayList<Integer> countAll = new ArrayList<Integer>();
    int count = 0;
    for(int i = 1; i <= M  ; i++){
      for(int j = 0; j < love.size(); j++){
        int jd = love.get(j);
        if(jd == i){
          count = count + 1;
        }
      }
      countAll.add(count);
      count = 0;
    }
      
    int lastCount = 0;
    for(int i = 0; i < countAll.size() ; i++){
      if(countAll.get(i) == N){
        lastCount++;
      }
    }
    System.out.println(lastCount);   
    }
  }  
}