N,M=io.read("*n","*n")
T={}
for i=1, M do
    T[i]=0
end
for i=1, N do
    K=io.read("*n")
    for j=1, K do
        A=io.read("*n")
        T[A]=T[A]+1
    end
end
counter=0
for i=1, M do
    if T[i]==N then
        counter=counter+1
    end
end
print(counter)