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