n, m = list(map(int, input().split()))





lst_sw = []

for _ in range(m):

    lst_sw.append(list(map(int, input().split())))

lst_p = list(map(int, input().split()))





ans = 0

for bits in range(2 ** n):

    judge = True

    for i in range(m):

        cnt = 0

        for j in range(1, len(lst_sw[i])):

            sw = lst_sw[i][j]

            if (bits >> (sw - 1)) & 1:

            # if (1 << (sw - 1)) & bits: # こちらの判定でも良い

                cnt += 1

        if cnt%2 != lst_p[i]:

            judge = False

    if judge:

        ans += 1





print(ans)

n, m = list(map(int, input().split()))





lst_sw = []

for _ in range(m):

    lst_sw.append(list(map(int, input().split())))

lst_p = list(map(int, input().split()))





ans = 0

for bits in range(2 ** n):

    judge = True

    for i in range(m):

        cnt_sw_on = 0

        for j in range(1, len(lst_sw[i])):

            sw = lst_sw[i][j]

            if (bits >> (sw - 1)) & 1:

                cnt_sw_on += 1

        if cnt_sw_on % 2 != lst_p[i]:

            judge = False

            break

    if judge:

        ans += 1





print(ans)

n, m = list(map(int, input().split()))
lst_sw = []
for _ in range(m):
    lst_sw.append(list(map(int, input().split())))
lst_p = list(map(int, input().split()))
ans = 0
for bits in range(2**n):
    judge = True
    for i in range(m):
        cnt = 0
        for j in range(1, len(lst_sw[i])):
            sw = lst_sw[i][j]
            if (bits >> (sw - 1)) & 1:
                # if (1 << (sw - 1)) & bits: # こちらの判定でも良い
                cnt += 1
        if cnt % 2 != lst_p[i]:
            judge = False
    if judge:
        ans += 1
print(ans)

n, m = list(map(int, input().split()))
lst_sw = []
for _ in range(m):
    lst_sw.append(list(map(int, input().split())))
lst_p = list(map(int, input().split()))
ans = 0
for bits in range(2**n):
    judge = True
    for i in range(m):
        cnt_sw_on = 0
        for j in range(1, len(lst_sw[i])):
            sw = lst_sw[i][j]
            if (bits >> (sw - 1)) & 1:
                cnt_sw_on += 1
        if cnt_sw_on % 2 != lst_p[i]:
            judge = False
            break
    if judge:
        ans += 1
print(ans)

-        cnt = 0 +        cnt_sw_on = 0 -                # if (1 << (sw - 1)) & bits: # こちらの判定でも良い -                cnt += 1 -        if cnt % 2 != lst_p[i]: +                cnt_sw_on += 1 +        if cnt_sw_on % 2 != lst_p[i]: +            break