'use strict'
function main(input) {
  input = input.split('\n')
  const config = input.shift().split(' ')
  input = input.map(row => row.slice(1) + ' ')
  let count = 0
  for (let i = 1; i <= config[1]; i++) {
    let temp = input.filter(row => row.indexOf(' ' + i + ' ') !== -1)
    if (temp.length === Number(config[0])) count++
  }
  console.log(count)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
