N,M=[int(i) for i in input().split()]
list=[];list1=[];list3=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
for i in range(M):
  list+=[int(i) for i in input().split()]
  list1+=[list]
  list=[]
#  print(list1)
list2 = [int(i) for i in input().split()]
#print(list2)
for i in range(M):
  for j in range(list1[i][0]):
    n=list1[i][j+1]
#    print(i,j,n)
    if list3[n]==-1:list3[n]=list2[i]
    if list3[n]==-2:continue
    if list3[n]!=list2[i]:list3[n]=-2
#print(list1,list2,list3)
print(2**(list3.count(0)+list3.count(1)))