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

public class Main{  
  public static void main(String[] args){   
    Scanner scn = new Scanner(System.in);
    int n = scn.nextInt();
    int m = scn.nextInt();   
    ArrayList<Integer> a = new ArrayList<>();
    for(int i=0; i<n ; i++){
      int k = scn.nextInt();
      int[] b = new int[k];
       for(int j=0; j<k ; j++){
         b[j] = scn.nextInt();
         a.add(b[j]);
       }   
    }
    Collections.sort(a);
    ArrayList<Integer> c = new ArrayList<>();
    int count = 0;
    for(int i=1; i<=m  ; i++){
      for(int j = 0; j < a.size(); j++){
        int x = a.get(j);
        if(x == i){
          count = count + 1;
        }
      }
      c.add(count);
      count = 0;
    }
      
    int count2 = 0;
    for(int i=0; i<c.size(); i++){
      if(c.get(i) == n){
        count2 = count2 + 1;
      }
    }
    System.out.println(count2);   
  }  
} 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 scn = new Scanner(System.in);
    int n = scn.nextInt();
    int m = scn.nextInt();   
    ArrayList<Integer> a = new ArrayList<>();
    for(int i=0; i<n ; i++){
      int k = scn.nextInt();
      int[] b = new int[k];
       for(int j=0; j<k ; j++){
         b[j] = scn.nextInt();
         a.add(b[j]);
       }   
    }
    Collections.sort(a);
    ArrayList<Integer> c = new ArrayList<>();
    int count = 0;
    for(int i=1; i<=m  ; i++){
      for(int j = 0; j < a.size(); j++){
        int x = a.get(j);
        if(x == i){
          count = count + 1;
        }
      }
      c.add(count);
      count = 0;
    }
      
    int count2 = 0;
    for(int i=0; i<c.size(); i++){
      if(c.get(i) == n){
        count2 = count2 + 1;
      }
    }
    System.out.println(count2);   
  }  
} Main public static void main(String[] args){   
    Scanner scn = new Scanner(System.in);
    int n = scn.nextInt();
    int m = scn.nextInt();   
    ArrayList<Integer> a = new ArrayList<>();
    for(int i=0; i<n ; i++){
      int k = scn.nextInt();
      int[] b = new int[k];
       for(int j=0; j<k ; j++){
         b[j] = scn.nextInt();
         a.add(b[j]);
       }   
    }
    Collections.sort(a);
    ArrayList<Integer> c = new ArrayList<>();
    int count = 0;
    for(int i=1; i<=m  ; i++){
      for(int j = 0; j < a.size(); j++){
        int x = a.get(j);
        if(x == i){
          count = count + 1;
        }
      }
      c.add(count);
      count = 0;
    }
      
    int count2 = 0;
    for(int i=0; i<c.size(); i++){
      if(c.get(i) == n){
        count2 = count2 + 1;
      }
    }
    System.out.println(count2);   
  } main {   
    Scanner scn = new Scanner(System.in);
    int n = scn.nextInt();
    int m = scn.nextInt();   
    ArrayList<Integer> a = new ArrayList<>();
    for(int i=0; i<n ; i++){
      int k = scn.nextInt();
      int[] b = new int[k];
       for(int j=0; j<k ; j++){
         b[j] = scn.nextInt();
         a.add(b[j]);
       }   
    }
    Collections.sort(a);
    ArrayList<Integer> c = new ArrayList<>();
    int count = 0;
    for(int i=1; i<=m  ; i++){
      for(int j = 0; j < a.size(); j++){
        int x = a.get(j);
        if(x == i){
          count = count + 1;
        }
      }
      c.add(count);
      count = 0;
    }
      
    int count2 = 0;
    for(int i=0; i<c.size(); i++){
      if(c.get(i) == n){
        count2 = count2 + 1;
      }
    }
    System.out.println(count2);   
  } Scanner scn = new Scanner(System.in); scn new Scanner(System.in) int n = scn.nextInt(); n scn.nextInt() scn.nextInt scn int m = scn.nextInt(); m scn.nextInt() scn.nextInt scn ArrayList<Integer> a = new ArrayList<>(); a new ArrayList<>() for(int i=0; i<n ; i++){
      int k = scn.nextInt();
      int[] b = new int[k];
       for(int j=0; j<k ; j++){
         b[j] = scn.nextInt();
         a.add(b[j]);
       }   
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      int k = scn.nextInt();
      int[] b = new int[k];
       for(int j=0; j<k ; j++){
         b[j] = scn.nextInt();
         a.add(b[j]);
       }   
    } {
      int k = scn.nextInt();
      int[] b = new int[k];
       for(int j=0; j<k ; j++){
         b[j] = scn.nextInt();
         a.add(b[j]);
       }   
    } int k = scn.nextInt(); k scn.nextInt() scn.nextInt scn int[] b = new int[k]; b new int[k] k for(int j=0; j<k ; j++){
         b[j] = scn.nextInt();
         a.add(b[j]);
       } int j=0; int j=0; j 0 j<k j k j++ j++ j {
         b[j] = scn.nextInt();
         a.add(b[j]);
       } {
         b[j] = scn.nextInt();
         a.add(b[j]);
       } b[j] = scn.nextInt() b[j] b j scn.nextInt() scn.nextInt scn a.add(b[j]) a.add a b[j] b j Collections.sort(a) Collections.sort Collections a ArrayList<Integer> c = new ArrayList<>(); c new ArrayList<>() int count = 0; count 0 for(int i=1; i<=m  ; i++){
      for(int j = 0; j < a.size(); j++){
        int x = a.get(j);
        if(x == i){
          count = count + 1;
        }
      }
      c.add(count);
      count = 0;
    } int i=1; int i=1; i 1 i<=m i m i++ i++ i {
      for(int j = 0; j < a.size(); j++){
        int x = a.get(j);
        if(x == i){
          count = count + 1;
        }
      }
      c.add(count);
      count = 0;
    } {
      for(int j = 0; j < a.size(); j++){
        int x = a.get(j);
        if(x == i){
          count = count + 1;
        }
      }
      c.add(count);
      count = 0;
    } for(int j = 0; j < a.size(); j++){
        int x = a.get(j);
        if(x == i){
          count = count + 1;
        }
      } int j = 0; int j = 0; j 0 j < a.size() j a.size() a.size a j++ j++ j {
        int x = a.get(j);
        if(x == i){
          count = count + 1;
        }
      } {
        int x = a.get(j);
        if(x == i){
          count = count + 1;
        }
      } int x = a.get(j); x a.get(j) a.get a j if(x == i){
          count = count + 1;
        } x == i x i {
          count = count + 1;
        } count = count + 1 count count + 1 count 1 c.add(count) c.add c count count = 0 count 0 int count2 = 0; count2 0 for(int i=0; i<c.size(); i++){
      if(c.get(i) == n){
        count2 = count2 + 1;
      }
    } int i=0; int i=0; i 0 i<c.size() i c.size() c.size c i++ i++ i {
      if(c.get(i) == n){
        count2 = count2 + 1;
      }
    } {
      if(c.get(i) == n){
        count2 = count2 + 1;
      }
    } if(c.get(i) == n){
        count2 = count2 + 1;
      } c.get(i) == n c.get(i) c.get c i n {
        count2 = count2 + 1;
      } count2 = count2 + 1 count2 count2 + 1 count2 1 System.out.println(count2) System.out.println System.out System System.out count2 String[] args args public class Main{  
  public static void main(String[] args){   
    Scanner scn = new Scanner(System.in);
    int n = scn.nextInt();
    int m = scn.nextInt();   
    ArrayList<Integer> a = new ArrayList<>();
    for(int i=0; i<n ; i++){
      int k = scn.nextInt();
      int[] b = new int[k];
       for(int j=0; j<k ; j++){
         b[j] = scn.nextInt();
         a.add(b[j]);
       }   
    }
    Collections.sort(a);
    ArrayList<Integer> c = new ArrayList<>();
    int count = 0;
    for(int i=1; i<=m  ; i++){
      for(int j = 0; j < a.size(); j++){
        int x = a.get(j);
        if(x == i){
          count = count + 1;
        }
      }
      c.add(count);
      count = 0;
    }
      
    int count2 = 0;
    for(int i=0; i<c.size(); i++){
      if(c.get(i) == n){
        count2 = count2 + 1;
      }
    }
    System.out.println(count2);   
  }  
} public class Main{  
  public static void main(String[] args){   
    Scanner scn = new Scanner(System.in);
    int n = scn.nextInt();
    int m = scn.nextInt();   
    ArrayList<Integer> a = new ArrayList<>();
    for(int i=0; i<n ; i++){
      int k = scn.nextInt();
      int[] b = new int[k];
       for(int j=0; j<k ; j++){
         b[j] = scn.nextInt();
         a.add(b[j]);
       }   
    }
    Collections.sort(a);
    ArrayList<Integer> c = new ArrayList<>();
    int count = 0;
    for(int i=1; i<=m  ; i++){
      for(int j = 0; j < a.size(); j++){
        int x = a.get(j);
        if(x == i){
          count = count + 1;
        }
      }
      c.add(count);
      count = 0;
    }
      
    int count2 = 0;
    for(int i=0; i<c.size(); i++){
      if(c.get(i) == n){
        count2 = count2 + 1;
      }
    }
    System.out.println(count2);   
  }  
} Main
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;

public class Main{  
  public static void main(String[] args){   
    Scanner scn = new Scanner(System.in);
    int n = scn.nextInt();
    int m = scn.nextInt();   
    ArrayList<Integer> a = new ArrayList<>();
    for(int i=0; i<n ; i++){
      int k = scn.nextInt();
      int[] b = new int[k];
       for(int j=0; j<k ; j++){
         b[j] = scn.nextInt();
         a.add(b[j]);
       }   
    }
    Collections.sort(a);
    ArrayList<Integer> c = new ArrayList<>();
    int count = 0;
    for(int i=1; i<=m  ; i++){
      for(int j = 0; j < a.size(); j++){
        int x = a.get(j);
        if(x == i){
          count = count + 1;
        }
      }
      c.add(count);
      count = 0;
    }
      
    int count2 = 0;
    for(int i=0; i<c.size(); i++){
      if(c.get(i) == n){
        count2 = count2 + 1;
      }
    }
    System.out.println(count2);   
  }  
}
