import sys

#import numpy as np



s2nn = lambda s: [int(c) for c in s.split(' ')]

ss2nn = lambda ss: [int(s) for s in ss]

ss2nnn = lambda ss: [s2nn(s) for s in ss]

i2s = lambda: sys.stdin.readline().rstrip()

i2n = lambda: int(i2s())

i2nn = lambda: s2nn(i2s())

ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]

ii2nn = lambda n: ss2nn(ii2ss(n))

ii2nnn = lambda n: ss2nnn(ii2ss(n))



import itertools



def main():

    N, M = i2nn()

    KS = ii2nnn(M)

    P = i2nn()

    judges = [[] for _ in range(M)]

    for i, ks in enumerate(KS):

        p = P[i]

        k = ks[0]

        s = ks[1:]

        while True:

            if p > len(s):

                break

            for pattern in itertools.combinations(s, p):

                d = [-1] * N

                for j in s:

                    d[j-1] = 0

                for j in pattern:

                    d[j-1] = 1

                judges[i].append(d)

            p += 2

    #print(judges)

    L = 2 ** N

    n = 0

    for i in range(L):

        sw = getDigits(i, N)

        #print(sw)

        a = True

        for judge in judges:

            b = False

            for ju in judge:

                c = True

                for j, k in zip(sw, ju):

                    if k == -1:

                        continue

                    elif j == k:

                        continue

                    else:

                        c = False

                        break

                if c:

                    b = True

                    break

            if b == False:

                a = False

                break

        if a:

            n += 1

    print(n)



def getDigits(n, maxlen):

    digits = [0] * maxlen

    i = 0

    while True:

        digits[i] = n % 2

        i += 1

        n = int(n / 2)

        if n == 0 or i >= maxlen:

            break

    return digits



main()

import sys

from collections import deque  # 双方向キュー

from collections import defaultdict  # 初期化済み辞書

from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー

from bisect import bisect_left, bisect_right  # 二分探索

#import numpy as np  # 1.8.2

#import scipy  # 0.13.3

#sys.setrecursionlimit(int(1e+6))

s2nn = lambda s: [int(c) for c in s.split(' ')]

ss2nn = lambda ss: [int(s) for s in ss]

ss2nnn = lambda ss: [s2nn(s) for s in ss]

i2s = lambda: sys.stdin.readline().rstrip()

i2n = lambda: int(i2s())

i2nn = lambda: s2nn(i2s())

ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]

ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]

ii2nn = lambda n: ss2nn(ii2ss(n))

ii2nnn = lambda n: ss2nnn(ii2ss(n))

MOD = int(1e+9) + 7



# bitリスト

def getBitsL(n, L):

    bits = [0] * L

    for i in range(L):

        bits[i] = (n & 1) == 1

        n >>= 1

    return bits



def main():

    N, M = i2nn()

    KS = ii2nnn(M)

    P = i2nn()

    n = 0

    for i in range(2**N):

        bits = getBitsL(i, N)

        b = True

        for j, ks in enumerate(KS):

            t = 0

            for k in ks[1:]:

                if bits[k-1]:

                    t += 1

            if t % 2 != P[j]:

                b = False

        if b:

            n += 1

    print(n)



main()

import sys

# import numpy as np
s2nn = lambda s: [int(c) for c in s.split(" ")]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
import itertools


def main():
    N, M = i2nn()
    KS = ii2nnn(M)
    P = i2nn()
    judges = [[] for _ in range(M)]
    for i, ks in enumerate(KS):
        p = P[i]
        k = ks[0]
        s = ks[1:]
        while True:
            if p > len(s):
                break
            for pattern in itertools.combinations(s, p):
                d = [-1] * N
                for j in s:
                    d[j - 1] = 0
                for j in pattern:
                    d[j - 1] = 1
                judges[i].append(d)
            p += 2
    # print(judges)
    L = 2**N
    n = 0
    for i in range(L):
        sw = getDigits(i, N)
        # print(sw)
        a = True
        for judge in judges:
            b = False
            for ju in judge:
                c = True
                for j, k in zip(sw, ju):
                    if k == -1:
                        continue
                    elif j == k:
                        continue
                    else:
                        c = False
                        break
                if c:
                    b = True
                    break
            if b == False:
                a = False
                break
        if a:
            n += 1
    print(n)


def getDigits(n, maxlen):
    digits = [0] * maxlen
    i = 0
    while True:
        digits[i] = n % 2
        i += 1
        n = int(n / 2)
        if n == 0 or i >= maxlen:
            break
    return digits


main()

import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索

# import numpy as np  # 1.8.2
# import scipy  # 0.13.3
# sys.setrecursionlimit(int(1e+6))
s2nn = lambda s: [int(c) for c in s.split(" ")]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e9) + 7
# bitリスト
def getBitsL(n, L):
    bits = [0] * L
    for i in range(L):
        bits[i] = (n & 1) == 1
        n >>= 1
    return bits


def main():
    N, M = i2nn()
    KS = ii2nnn(M)
    P = i2nn()
    n = 0
    for i in range(2**N):
        bits = getBitsL(i, N)
        b = True
        for j, ks in enumerate(KS):
            t = 0
            for k in ks[1:]:
                if bits[k - 1]:
                    t += 1
            if t % 2 != P[j]:
                b = False
        if b:
            n += 1
    print(n)


main()

+from collections import deque  # 双方向キュー +from collections import defaultdict  # 初期化済み辞書 +from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー +from bisect import bisect_left, bisect_right  # 二分探索 -# import numpy as np +# import numpy as np  # 1.8.2 +# import scipy  # 0.13.3 +# sys.setrecursionlimit(int(1e+6)) +ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)] -import itertools +MOD = int(1e9) + 7 +# bitリスト +def getBitsL(n, L): +    bits = [0] * L +    for i in range(L): +        bits[i] = (n & 1) == 1 +        n >>= 1 +    return bits -    judges = [[] for _ in range(M)] -    for i, ks in enumerate(KS): -        p = P[i] -        k = ks[0] -        s = ks[1:] -        while True: -            if p > len(s): -                break -            for pattern in itertools.combinations(s, p): -                d = [-1] * N -                for j in s: -                    d[j - 1] = 0 -                for j in pattern: -                    d[j - 1] = 1 -                judges[i].append(d) -            p += 2 -    # print(judges) -    L = 2**N -    for i in range(L): -        sw = getDigits(i, N) -        # print(sw) -        a = True -        for judge in judges: -            b = False -            for ju in judge: -                c = True -                for j, k in zip(sw, ju): -                    if k == -1: -                        continue -                    elif j == k: -                        continue -                    else: -                        c = False -                        break -                if c: -                    b = True -                    break -            if b == False: -                a = False -                break -        if a: +    for i in range(2**N): +        bits = getBitsL(i, N) +        b = True +        for j, ks in enumerate(KS): +            t = 0 +            for k in ks[1:]: +                if bits[k - 1]: +                    t += 1 +            if t % 2 != P[j]: +                b = False +        if b: -def getDigits(n, maxlen): -    digits = [0] * maxlen -    i = 0 -    while True: -        digits[i] = n % 2 -        i += 1 -        n = int(n / 2) -        if n == 0 or i >= maxlen: -            break -    return digits - -