process.stdin.resume();
process.stdin.setEncoding('utf8');
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
 var input = lines[0].split(' ');
 var N = parseInt(input[0]);
 var M = parseInt(input[1]);
 var arr = new Array(M).fill(0);
//console.log(arr)
 for (var i = N ; i > 0 ; i--) {
   var prefer = lines[i].split(' ');
   for (var turn = 1 ; turn <= parseInt(prefer[0]) ; turn++) {
     //console.log(prefer[turn])
     arr[parseInt(prefer[turn]) - 1] += 1;
   }
   //console.log(arr);
}
  var count = 0;
  for (var j = 0 ; j < M ; j++) {
    if (arr[j] === N) {
      count += 1;
    }
  }
console.log(count);
});