'use strict'

function main(input) {
  input = input.split('\n').map(v => v.split(' ').map(v => ~~v))
  const n = input[0][0]
  const m = input[0][1]
  const ans = input.slice(1, -1)
  const counts = Array.apply(null, { length: m + 1 }).fill(0)
  for (let i = 0; i < n; i++) {
    for (let j = 1; j <= ans[i][0]; j++) {
      counts[ans[i][j]] += 1
    }
  }

  const f = counts.filter(v => {
    return v >= n
  })

  console.log(f.length)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))