n,k=list(map(int,input().split()))
a=[]
for i in range(k):
    p=list(map(int,input().split()))
    p=p[1:]
    a.append(p)
r=list(map(int,input().split()))
ans=0
cou=0
for i in range(k):
    for j in range(k):
        if a[i]==a[j]:
            if r[i]!=r[j]:
                ans=1
            else:
                cou+=1
cou-=k
cou/=2
k-=cou
if n<k:
    print(0)
else:
    print(int(2**(n-k)))