let NM: [Int] = readLine()!.split(separator: " ").map { Int($0)! }
var num: [Int] = Array(repeating: 0, count: NM[1])
for _ in 1...NM[0] {
    
    for A in readLine()!.split(separator: " ").map({ Int($0)! }).dropFirst() {
        num[A-1] += 1
    }
}
var res: Int = 0
for a in num {
    if a == NM[0] { res += 1}
}
print(res)