'use strict'

function main(input) {
  input = input
    .trim()
    .split('\n')
    .map(v => v.split(' ').map(Number))

  const N = input[0][0]
  const M = input[0][1]

  const enq = input.slice(1)
  const votebox = [...Array(M + 1)].map(v => 0)
  enq.forEach(item => {
    for (let i = 1; i < item.length; i++) {
      votebox[item[i]]++
    }
  })
  const ans = votebox.filter(num => {
    return num === N
  })
  console.log(ans.length)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))
