N,M=map(int,input().split())
ls3 = []
for i in range(M):
    ls1=list(map(int,input().split()))
    ls1.pop(0)
    ls3.append(ls1)
ls2 = list(map(int,input().split()))

ii = 0
for i in range(2**N):
    ls4 = [0]*M
    for j in range(N):
        if (i>>j&1):
            for k in range(M):
                if j in ls3[k]:
                    ls4[k] += 1
    
    if sum(ls4) == M:
        ii += 1

print(ii)