N,M=map(int,input().split(" "))
List=[input().split(" ") for _ in range(M)]
P=[int(s) for s in input().split(" ")]

a=[]
for i in range(M):
    for j in range(1,int(List[i][0])+1):
        a.append(int(List[i][j]))
     

count=0
for i in range(1,N+1):
    if 0<=a.count(i)<2:
        count+=1
        
print(2**(count-1) if count!=0 else 0)