function main(arg) {
	var arg = arg.split("\n")
	var tmp = arg.shift()
	var N = Number(tmp.split(" ")[0])
	var M = Number(tmp.split(" ")[1])

	var A = []

	var result = new Array(M + 1).fill(0)

	for (var i = 0; i < arg.length; i++) {
		var tmp = arg[i].split(" ")
		tmp.shift()
		// A.push()
		var row = tmp.map(Number)
		for (var j = 0; j < row.length; j++) {
			var index = row[j]
			result[index]++
		}
	}

	var count = 0

	for (var i = 0; i < result.length; i++) {
		if (result[i] === N) {
			count++
		}
	}
	// console.log(result)
	console.log(count)

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));