N=io.read("n")
M=io.read("n")
k={}
A={}
t={}
for i=1,N do
  k[i]=io.read("n")
  A[i]={}
  for j=1,k[i] do
    A[i][j]=io.read("n")
    t[A[i][j]]=(t[A[i][j]] or 0)+1
  end
end
local count=0
for i,v in pairs(t) do
  if v==M then
    count=count+1
  end
end
print(count)
    
  