INTEGER N,M,ANS
INTEGER,ALLOCATABLE,DIMENSION(:)::E
INTEGER K(30)
INTEGER A(30,30)
READ*,N,M
ALLOCATE(E(M))
E=0
DO I=1,N
  READ*,K(I),(A(I,J),J=1,K(I))
  DO J=1,K(I)
    E(A(I,J))=E(A(I,J))+1
  END DO
END DO
ANS=0
DO I=1,M
  IF(E(I)==N)ANS=ANS+1
END DO
PRINT"(I0)",ANS
END