import numpy as np
N,M  = map(int,input().split())
coeff = np.zeros((M,N))
for i in range(M):
    inputs = list(map(int,input().split()))
    for switch in inputs[1:]:
        coeff[i][switch-1] = 1
onlist = list(map(int,input().split()))
extension = np.zeros((M,N+1))
extension[:,:N] = coeff
extension[:,N] = onlist
rankcoeff = np.linalg.matrix_rank(coeff)
rankext = np.linalg.matrix_rank(extension)
# print(rankcoeff,rankext)
if rankcoeff != rankext:
    print(0)
else:
    ans = 2**(N-rankcoeff)
    print(ans)

# cardlist = list(map(int,input().split()))