def c_switches(N, M, Switches, P):
    import numpy
    a = [[0] * N for _ in range(M)]
    ap = [[0] * (N + 1) for _ in range(M)]
    for t, (_, *switches) in enumerate(Switches):
        for s in switches:
            a[t][s - 1] = 1
            ap[t][s - 1] = 1
        ap[t][-1] = P[t]
    a = numpy.array(a)
    ap = numpy.array(ap)
    a_rank = numpy.linalg.matrix_rank(a)
    ap_rank = numpy.linalg.matrix_rank(ap)
    if a_rank != ap_rank:
        ans = 0
    else:
        ans = 2**(N - a_rank)
    return ans

N, M = [int(i) for i in input().split()]
Switches = [[int(i) for i in input().split()] for j in range(M)]
P = [int(i) for i in input().split()]
print(c_switches(N, M, Switches, P))