import numpy as np

N,M=list(map(int,input().split()))

A=np.zeros((N+1,M+1))

A[0]=np.ones(M+1)

for i in range(1,N+1):

    B=list(map(int,input().split()))

    for m in range(1,B[0]+1):

        A[i][B[m]]=A[i-1][B[m]]

a=sum(A[N])

print((int(a)))
N,M=list(map(int,input().split()))

A = [[1 for _ in range(M)]]+[[0 for _ in range(M)] for _ in range(N)]

for i in range(1,N+1):

    B=list(map(int,input().split()))

    Ai=B[1:]

    for m in Ai:

        A[i][m-1]=A[i-1][m-1]

a=sum(A[N])

print((int(a)))
import numpy as np

N, M = list(map(int, input().split()))
A = np.zeros((N + 1, M + 1))
A[0] = np.ones(M + 1)
for i in range(1, N + 1):
    B = list(map(int, input().split()))
    for m in range(1, B[0] + 1):
        A[i][B[m]] = A[i - 1][B[m]]
a = sum(A[N])
print((int(a)))

N, M = list(map(int, input().split()))
A = [[1 for _ in range(M)]] + [[0 for _ in range(M)] for _ in range(N)]
for i in range(1, N + 1):
    B = list(map(int, input().split()))
    Ai = B[1:]
    for m in Ai:
        A[i][m - 1] = A[i - 1][m - 1]
a = sum(A[N])
print((int(a)))

-import numpy as np - -A = np.zeros((N + 1, M + 1)) -A[0] = np.ones(M + 1) +A = [[1 for _ in range(M)]] + [[0 for _ in range(M)] for _ in range(N)] -    for m in range(1, B[0] + 1): -        A[i][B[m]] = A[i - 1][B[m]] +    Ai = B[1:] +    for m in Ai: +        A[i][m - 1] = A[i - 1][m - 1]